[Overview]sort Examples
sort - sort lines of text files
sort [OPTION]... [FILE]...
-b: ignore leading blanks
-f: fold lower case to upper case characters
-n: compare according to string numerical value
-R: sort by random hash of keys
-r: reverse the result of comparisons
-c: check for sorted input; do not sort
-k: start a key at POS1 (origin 1), end it at POS2 (default end of line)
-o: write result to FILE instead of standard output
-t: use SEP instead of non-blank to blank transition
for further information see the manual pages sort(1)
- sort entries by last name
sort -k2 ../data/full-name.txt
[Output]
- sort by country (second column) and inside a country by decreasing population (4. column)
sort -t, -k2,2 -k4,4nr ../data/city.sample.csv
[Output]
- Lottery-forecast (6 from 49)
seq 1 49 | sort -R | head -n6
[Output]
- read the country specific city-files and sort them, based on the name of the city
sort -t, -k1 ../data/city-*.csv
[Output]
- check, if input is sorted
seq 1 5 | sort -c && echo $?
[Output]
- check, if input is sorted
seq 1 5 | sort -R | sort -c 2>&1 | tee /dev/null
[Output]
all examples assembled by andreas schmidt for the IC3K 2022 conference