Created
December 3, 2021 11:42
-
-
Save MartGro/d4ea00c899d0b649be93604bad801c94 to your computer and use it in GitHub Desktop.
Sort CSV file based on numerical value of fist field (shell command)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ head -n1 unsorted.csv && tail -n+2 unsorted.csv | sort -n --field-separator="," -k 1,1; } > sorted.csv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a small shell command that uses the gnu sort command to sort a csv file larger than memory.
It is quite fast.
References:
https://superuser.com/questions/33362/how-to-unix-sort-by-one-column-only
-> how to sort by a single column
https://stackoverflow.com/questions/2188199/how-to-use-double-or-single-brackets-parentheses-curly-braces
-> how to concatenate the output, Attention, the spaces and the semicolons are necessary
https://unix.stackexchange.com/questions/345076/sorting-csv-file-by-first-column-ignoring-header
-> how to sort keeping the header fixed