Sortix cross-nightly manual
This manual documents Sortix cross-nightly. You can instead view this document in the latest official manual.
NAME
sort — sort lines of textSYNOPSIS
| sort | [-bCcdfgihMmnRruVz] [-k key] [-o path] [-t separator] file ... |
DESCRIPTION
sort reads lines of text from the standard input and writes the lines in sorted order to the standard output. If files are specified, the input is the concatenated content of the files read in sequential order. The file path can be set to ‘-’ to specify the standard input. The lines are compared according to the current locale's collating rules.- -b, --ignore-leading-blanks
- Ignore leading blank characters (space and tab) when determining fields.
- -c, --check, --check=diagnose-first
- Check whether the input is already sorted. If a line is out of order (or an equal line is found if -u), write an error describing which line was out of order and exit 1.
- -C, --check=quiet, --check=silent
- Same as -c, but write no error to the standard output about the input being out of order.
- -d, --dictionary-order
- Only alphanumeric and blank characters are significant when comparing.
- -f, --ignore-case
- Compare lowercase characters as if they were uppercase.
- -g, --general-numeric-sort, --sort=general-numeric
- Compare the strings as floating-pointer numbers parsed with strtod(3).
- -i, --ignore-nonprinting
- Ignore non-printable characters when comparing.
- -k key, --key=key
-
Add another sorting key in order of decreasing priorities with the format:starting_field[modifier][,ending_field[modifier]]The lines are split into fields per the -t option. Each key compares lines starting from the start of the starting_field until the end of the ending_field. If every key compares equal, the lines are compared with strcoll(3) as a fallback. Optional modifier strings using characters from the set bdfghiMnRrV select the comparison behavior from the option by that name. If no keys are specified, a key is added spanning the whole line.
- -h, --human-numeric-sort, --sort=human-numeric
- Compare numeric values followed by a unit magnitude character from the YZEPTGMKk set.
- -M, --month-sort, --sort=month
- Compare month names.
- -m, --merge
- Merge the presorted input files into a sorted output.
- -n, --numeric-sort, --sort=numeric
- Compare numeric values.
- -o path, --output=path
- After reading the full input; write the output to the file at path (creating it if it does not already exist, discarding its previous contents if it already existed). The output file can be one of the input files. This option is incompatible with -C and -c.
- -R, --random-sort, --sort=random
- Sort the lines randomly with a uniform distribution, where all permutations are equally likely. This option is incompatible with -C and -c. If -u, don't write duplicate lines to the output.
- -r, --reverse
- Compare the lines in reverse order.
- -t separator, --field-separator=separator
- Use separator as the character that separates fields for use in -k. Each occurence of the character is significant. If -t is not specicied, fields are split on sequences of blank characters, where multiple occurences are not significant.
- -u, --unique
- Don't write a line if it is equal to the previous line.
- -V, --version-sort, --sort=version
- Sort according to the version string, per strverscmp(3).
- -z, --zero-terminated
- Lines are delimited with the NUL byte (0) instead of the newline byte (10).
IMPLEMENTATION NOTES
In the event of an input error, sort will write an error to the standard error and exit unsuccessfully.ENVIRONMENT
- LANG
- The default locale for locale variables that are unset or null.
- LC_ALL
- Overrides all the other locale variables if set.
- LC_COLLATE
- Compare the input according to this locale's collating rules using strcoll(3).
EXIT STATUS
sort will exit 0 on success, exit 1 if the input was out of order when -C or -c, or exit 2 (or higher) otherwise.EXAMPLES
Read lines from the standard input and write them in sorted order to the standard output:sort < input > output
grep pattern lines.txt | sort foo - bar -o output.txt
if sort -C file; [ $? = 1 ]; then sort file -o file fi
sort -u