How to ignore headers when merging single column of multiple CSV files? How to ignore headers when merging single column of multiple CSV files? unix unix

How to ignore headers when merging single column of multiple CSV files?


You can do it with awk, nearly as you have already done, by adding a condition on the FNR (the record number per file):

awk -F, 'FNR > 1 {print $3}' *.csv > merged.csv


Use tail and cut:

tail -q -n +2 *.csv | cut -f3 -d, > merged.csv
  • tail -n +2 prints all lines of files starting from line number 2
  • -q suppresses printing of file names
  • cut -f3 -d, extracts the third field, treating , as the delimiter


try: If you have to read only 2 files.

awk -F, 'FNR>1{print $(NF-1)}' file[12]

Here I am making field separator as comma and then checking if line number is greater than 1 then printing the second last field. Point to be noted here is file[12] will only read files named file1 and file2, if you have more than that files use file* then.