Living in the Shell #6; sort

Living in the Shell #6; sort

ยท

1 min read

sort ๐Ÿ†Ž

Sorts/randomizes input lines.

Sort lexically

echo -n 'Zack\nAdam\nCharles' | sort
Adam
Charles
Zack

Sort descending -r

echo -n 'Zack\nAdam\nCharles' | sort -r

Sort numerically -n

echo -n '10 Zack\n5 Adam\n1 Charles' | sort -n
1 Charles
5 Adam
10 Zack

Sort human-readable size numerics -h

echo -n '1G\n1K\n23MB' | sort -h
1K
23MB
1G

Check sorted state -c

echo -n 'Zack\nAdam\nCharles' | sort -c
sort: -:2: disorder: Adam

(Exits with a nonzero exit code that indicates unsorted input.)

Shuffle/randomize -R

echo -n 'Zack\nAdam\nCharles' | sort -R
ย