Unix script to remove the first line of a CSV file

旧城冷巷雨未停 提交于 2019-12-02 15:48:25

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)

Andrew Mellinger

While looking for this answer I also found this other thread. There they say use tail, which doesn't actually make an modifications which is what the OP wanted. You could over course copy to a temporary file. Additionally, if you were going to stream the files into another tool, you could use 'tail' in a pipe and never have to write temporary files or write to disk.

How can I remove the first line of a text file using bash/sed script?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!