Table of Contents

sort reference

sort -nr numbers.txt # descending numeric order
sort -k3 output.txt  # key3, omitting the first and second fields.
sort -f names.txt    # ignore case
sort -s names.txt    # stable sort
sort -u names.txt    # unique
sort -t: /etc/passwd # use ':' as the field delimiter

Sort an IP address list using sort command howto

# Sort by column2 and then column4, numerically, delimited by '.'
# while -k2  only specifies starting point is column2
# -k2,2  specifies both starting, and ending point. which means exact column2.

$ cat ips.txt | sort -t. -k 2,2n -k 4,4n