Merging Multiple CSV Files without merging the header
You'll need more than the cat
command, as described here:
Say you have 3 CSV-files: file1.csv
, file2.csv
, and file3.csv
and want to join them to bigfile.csv
and your header is always (only) the first line, then use
either (keep header from first file "file1.csv"):
cat file1.csv <(tail +2 file2.csv) <(tail +2 file3.csv) > bigfile.csv
or (remove header from all files who's names begin with "file"):
awk 'FNR > 1' file*.csv > bigfile.csv
I agree with the top answer but I suggest to extend it with the following scenario (as I can not comment):
If you want the output file to contain header (once) the correct script is:
awk '(NR == 1) || (FNR > 1)' file*.csv > bigfile.csv
FNR represents the number of the processed record in a single file. And NR represents it globally, so first line is accepted and the rest are ignored as before.