I split a number of csv files into two halves each. But every of those files had a header, so now the second halves of the files are missing headers.
How do I insert the top line of file A into the top of file B?
using command substitution to extract the first line of file1 and then using sed in place replacement for first line in file2.
sed -i "1s/^/$(head -n1 file1)\n/" file2
You have to rewrite the second file. Assuming that you have the files first.csv
and second.csv
you can do it like that:
head -n1 first.csv > second-new.csv
cat second.csv >> second-new.csv
You can now inspect second-new.csv
to see if everything is ok and then replace the old version with:
mv -i second-new.csv second.csv