sort command
The sort command, which puts lines in order, alphabetically by default.
In more detail
-n sorts by numeric value, -r reverses, -k picks a key column with -t setting the separator, and -u drops duplicates. -o file writes the result safely back over an input file, which a plain > redirect would empty first.
Examples
sort -t, -k3 -n sales.csvsort names.txt -o names.txtRelated terms
- uniq — The command that collapses runs of identical adjacent lines into one; -c prefixes each with how many there were.
- cut command — The cut command, which extracts columns from each line, either by character position or by fields split on a delimiter.
- redirection — Sending a command's output into a file instead of the terminal: > replaces the file, >> appends to the end of it.
Taught in
- Redirection: Truncate, Append, Both Streams — Bash Scripting & Command Line Automation
- Pipelines, tee And Process Substitution — Bash Scripting & Command Line Automation
- Finding Lines: grep And Regular Expressions — Bash Scripting & Command Line Automation
- Reshaping Text: cut, sort, uniq, tr, sed, awk — Bash Scripting & Command Line Automation
- find And xargs — Bash Scripting & Command Line Automation
- Archives, Transfers And The Network — Bash Scripting & Command Line Automation
- Scheduling, Monitoring And A Script That Reports — Bash Scripting & Command Line Automation