Sorting a CSV file preserving a header line

~ 1 min read

Given a CSV file (-t ',') called my.csv

Sort ascending by the third column (-k3)

Ignoring/preserving a header row as the first row (head -n 1)

Can be done with the following *nix command

(head -n 1; sort -u -t ',' -k3) <my.csv

The result will be sent to STDOUT but can easily be redirected to a file by appending a standard redirect (>my_new.csv)

all posts →