2

I am trying to delete the first row of each of my .csv files in my DIR folder using the sed:

DIR=/home/results for filename in "$DIR"; do sed 1d filename.csv done 

However, this doesn't work. I am new to bash scripting and would be thankful if anyone tells me how to fix this.

1

1 Answer 1

3

Just do:

for f in /home/results/*.csv; do sed -i '1 d' "$f"; done 

The glob pattern /home/results/*.csv matches all .csv files in /home/results/ directory and then the for construct iterate over the files, sed does the in place removal of the first row from each file.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much! This works and now I want to have a new row as a first line of this which I am trying to do by echo "col1, col2, col3" > all.csv but it doesnt work. Do you have suggestions for this?
@rehm20 You could do that using sed: for f in /home/results/*.csv; do sed -i '1 s/.*/col1, col2, col3/' "$f"; done

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.