问题
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