Copy the second line of a csv in one directory to a csv in another directory

青春壹個敷衍的年華 提交于 2021-01-29 16:11:35

问题


File.csv is in directory: /a/b/c/File.csv

I want to copy the second line of File.csv in output.csv which has to be created in directory /a

So the final output is:

/a/output.csv

I tried to run in directory /a the command:

sed -n '2p' /a/b/c/File.csv>output.csv

But it didn't work.

I also tried to run in directory /a/b/c the command: sed -n '2p' File.csv>/a/output.csv

But it dind't work

What am I doing wrong?


回答1:


The line number goes outside of the '' as in:

sed -n 2'p' sourcefile.csv > destfile.csv

Here, -n suppresses output of the unspecified line, and 'p' is the actual command to sed for what to do with line 2. By the way, you can separate the ">" redirection from the input and output file names, to make things a bit easier to read.




回答2:


Try this one:

head -2 /a/b/c/File.csv | tail -1 > /a/output.csv


来源:https://stackoverflow.com/questions/61779325/copy-the-second-line-of-a-csv-in-one-directory-to-a-csv-in-another-directory

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