sort -t, -k4 -nr data.csv | head -2

Category: Data Science & Analysis

sort -t, -k4 -nr data.csv | head -2

Sort a CSV by column 4 numerically and take the top 2

The -t, flag sets the comma field delimiter, -k4 selects column 4 as the key, and -nr sorts numerically in descending order. Piping the sorted output into head -2 keeps only the two highest rows. Because this is plain sort, the header row may end up in the middle of the output; CSV-aware tools like mlr sort keep headers on top. The pipe symbol (|) chains the two commands.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.