Search code examples
bashshellsortingunixcsv

Sort CSV file based on first column


Is there a way to sort a csv file based on the 1st column using some shell command?

I have this huge file with more than 150k lines hence I can do it in excel:( is there an alternate way ?


Solution

  • sort -k1 -n -t, filename should do the trick.

    -k1 sorts by column 1.

    -n sorts numerically instead of lexicographically (so "11" will not come before "2,3...").

    -t, sets the delimiter (what separates values in your file) to , since your file is comma-separated.