How to replace the header of a file with the header of another file
If you insist to do it with sed
:
( sed 1q file2.csv; sed 1d file1.csv ) >file3.csv && mv file3.csv file1.csv
Without sed
:
( head -1 file2.csv; tail -n +2 file1.csv ) >file3.csv && mv file3.csv file1.csv
You could escape any backslash in the 1st line in file2.csv
, prepend 1c\
and a newline and q
uit, piping the resulting two lines to another sed
that reads its script file from stdin
:
sed 's/\\/&&/g;x;s/.*/1c\\/;G;q' file2.csv | sed -i -f - file1.csv
or with ed
, open file1.csv
and read in file2.csv
header after 1st line then delete 1st line:
ed -s file1.csv <<\IN
1r ! head -n1 file2.csv
1d
w
q
IN