Unix script to remove the first line of a CSV file
I tried to delete the first row from a CSV, cd into the location and then the answer to the question didn't work for me, was getting
sed: can't read 1d: No such file or directory
So, I've used the following stated here by @amit
sed -i '1d' filename.csv
You can delete the first line of a file using sed
:
sed -i '' 1d file.csv
If you just want to get the contents of the file without the first line, and without modifying the file, remove the -i ''
flag:
sed 1d file.csv
Here 1d is the command to execute:
- 1 => line where to act
- d => delete
So 1d means 'delete line 1'
If you want to get the first line, you can use sed too:
sed -n 1p file.csv
Here p stands for 'print' or
sed 1q file.csv
(see William Pursell's comment)