Sort
Table of Contents
- sort
- Sort a file in ascending order:
- Sort a file in descending order:
- Sort a file in case-insensitive way:
- Ignore non-printable characters
- Sort a file using numeric rather than alphabetic order:
- Sort `/etc/passwd` by the 3rd field of each line numerically, using “:” as a field separator:
- Sort a file preserving only unique lines:
- Sort a file, printing the output to the specified output file (can be used to sort a file in-place):
- Sort randomly:
sort
Sort lines of text files.
Sort a file in ascending order:
sort path/to/file
Sort a file in descending order:
sort -r path/to/file
Sort a file in case-insensitive way:
sort -f path/to/file
Ignore non-printable characters
sort -i path/to/file
Sort a file using numeric rather than alphabetic order:
sort -n path/to/file
Sort `/etc/passwd` by the 3rd field of each line numerically, using “:” as a field separator:
sort -t : -k 3n /etc/passwd
Sort a file preserving only unique lines:
sort -u path/to/file cat /etc/shells | awk -F "/" '/^\// {print $NF}' | sort -u
Sort a file, printing the output to the specified output file (can be used to sort a file in-place):
sort path/to/file/read -o path/to/file/output
NOTE:
the output file is the one immediately after the -o flag!
Sort randomly:
sort -R .bashrc
NOTE:
. This is like a random permutation of the inputs (see shuf invocation), except that keys with the same value sort together.
Footer
Copyright © 2020-2021 Derek Taylor (DistroTube)
This page is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License (CC-BY-ND 4.0).
The source code for distro.tube can be found on GitLab. User-submitted contributions to the site are welcome, as long as the contributor agrees to license their submission with the CC-BY-ND 4.0 license.