Sorting CSV file by first column, ignoring header

csvsort

How would I sort a CSV file by the first column, where the first column a lowercase string, ignoring header line?

Best Answer

sort does not have an option to exclude header. You can remove the header using:

tail -n+2 yourfile | sort 

This tail syntax gets yourfile from second line up to the end of the file.

Of course the results of sort will not include the header.

You can isolate the header with command head -n1 yourfile which will print only the first line of your file (your header).

To combine them together you can run:

head -n1 yourfile && tail -n+2 yourfile | sort
Related Question