How do you sort by a specific column, numerically, and in reverse?
BeginnerConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
sort -t, -k3,3n data.csv # field 3, numeric, comma-separated
sort -k5,5nr report.txt # field 5 numeric, descending
du -sh /var/* | sort -h # human sizes: 512K < 3M < 2G
sort -u ips.txt # unique lines
sort -k2,2 -k1,1n file # by field 2, then field 1 numeric
sort -V versions.txt # version order: 1.9 < 1.10
Always give the end field (-k3,3); -k3 means "from field 3 to the end of line". Set LC_ALL=C for byte-order sorting that is fast and identical on every machine.
More on Text processing: grep, sed, awk, cut, sort, uniq
What are the most useful `grep` flags?BeginnerWhat is the difference between basic, extended and Perl regular expressions in grep?IntermediateWhat are the core `sed` commands you use in automation?BeginnerWhy does `sed -i` behave differently on macOS and Linux?IntermediateHow do you use variables inside a `sed` expression safely?AdvancedWhat is the structure of an `awk` program?Beginner