Bash

Sorting data using command line interface

sort some_data.csv
Sorts the some_data.csv file by alphabetical order (by default) and prints the result to your screen.


sort -n some_data.csv
Sorts the some_data.csv file by numerical order.


sort -r some_data.csv
Sorts the some_data.csv file by alphabetical order (by default) and in reverse.


sort -r -n some_data.csv
Sorts the some_data.csv file by numerical order and in reverse.


sort -u some_data.csv
Sorts the some_data.csv file and removes duplicates. (Note: -u stands for unique.)


sort -n -t',' -k2 some_data.csv
Sorts the some_data.csv file in numerical order -- and the column that it uses for sorting is the second column. The field separator is a comma (,).


uniq some_data.csv
Unifies repeated lines that follow each other.
Note: sort -u removes all duplicated rows. uniq removes only those duplicated rows that follow each other.


uniq -c some_data.csv
Unifies repeated lines that follow each other and counts the number of occurrences.