public final class Sort extends Object
NAME
sort - sort, merge, or sequence check text files
SYNOPSIS
sort | |
sort <args> | |
sort <files> | |
sort <inputs> | |
sort <comparator> | |
sort <comparator> <files> | |
sort <comparator> <paths> | |
sort <comparator> <inputs> | |
sort [-cmubdfnghMVr] | |
sort [-cmubdfnghMVr] <files> | |
sort [-cmubdfnghMVr] <paths> | |
sort [-cmubdfnghMVr] <inputs> | |
sort [-cmubdfnghMVr] <comparator> | |
sort [-cmubdfnghMVr] <comparator> <files> | |
sort [-cmubdfnghMVr] <comparator> <paths> | |
sort [-cmubdfnghMVr] <comparator> <inputs> |
See Sort.Interface
for the corresponding command signature methods.
DESCRIPTION
The sort utility performs one of the following functions:
Comparisons are based on one or more sort keys/fields extracted from each line of input. If no sort keys/fields are specified, comparisons are based on the entire line up to, but not including, the terminating <newline>. All comparisons are performed using the collating sequence of the current locale.
Sorting is stable, that is, the ordering of input lines is preserved if they are considered equal according to the current comparison criteria (if two lines originate from different input files, the index of the file in the input arguments list defines the ordering of the lines).
NOTES
dictionaryOrder
, humanNumericSort
, monthSort
, versionSort
Options
The following options are supported:
-c | --check | Checks that the single input file is ordered as specified by the arguments and the collating sequence of the current locale. No output is produced; only the exit code is affected. | |||
-m | --merge | Merge only; the input file are assumed to be already sorted. | |||
-u | --unique | Unique: suppress all but one in each set of lines having equal keys.
If used with the -c option, checks that there are no lines
with duplicate keys, in addition to checking that the input file is
sorted. | |||
-b | --ignoreLeadingBlanks | Ignore leading blanks. (This option is ignored if a comparator operand is present). | |||
-d | --dictionaryOrder | Consider only blanks and alphanumeric characters. (This option is ignored if a comparator operand is present). | |||
-f | --ignoreCase | Consider all lowercase characters that have uppercase equivalents to be the uppercase equivalent for the purposes of comparison. (This option is ignored if a comparator operand is present). | |||
-n | --numericSort | Sort numerically; the number begins each line and consists of
optional blanks, an optional minus sign, and zero or more digits
possibly separated by thousands separators, optionally followed by a
decimal-point character and zero or more digits. An empty number is
treated as '0'. The current local specifies the decimal-point
character and thousands separator.
Comparison is exact; there is no rounding error.
Neither a leading '+' nor exponential notation is recognized. To
compare such strings numerically, use the
(This option is ignored if a comparator operand is present). | |||
-g | --generalNumericSort | Sort numerically, using the standard Double.parseDouble(String)
function to convert a trimmed line to a double-precision floating
point number. This allows floating point numbers to be specified in
scientific notation, like 1.0e-34 and 10e100.
Uses the following collating sequence: Lines that cannot be parsed because they do not represent valid double values (in alpha-numeric order); "-Infinity"; finite numbers in ascending numeric order (with -0 < +0); "Infinity"; "NaN".
This option is usually slower than (This option is ignored if a comparator operand is present). | |||
-h | --humanNumericSort | Sort numerically, first by numeric sign (negative, zero, or
positive); then by SI suffix (either empty, or 'k' or 'K', or one
of 'MGTPEZY', in that order); and finally by numeric value. For
example, '1023M' sorts before '1G' because 'M' (mega) precedes 'G'
(giga) as an SI suffix.
This option sorts values that are consistently scaled to the nearest
suffix, regardless of whether suffixes denote powers of 1000 or
1024, and it therefore sorts the output of any single invocation of
the
The syntax for numbers is the same as for the
(This option is ignored if a comparator operand is present). | |||
-M | --monthSort | An initial string, consisting of any amount of blanks, followed by a month name abbreviation, is folded to UPPER case and compared in the order: (unknown) < 'JAN' < ... < 'DEC'. The current locale determines the month spellings. | |||
-V | --versionSort | Sort by version name and number. It behaves like a standard sort,
except that each sequence of decimal digits is treated numerically
as an index/version number.
(This option is ignored if a comparator operand is present). | |||
-r | --reverse | Reverse the sense of comparisons. |
OPERANDS
The following operands are supported:
<paths> | : | String... | Path names of the files to be sorted, merged, or checked; wildcards * and ? are supported; relative paths are resolved on the basis of the current working directory. | ||
<files> | : | java.io.File... | The files to be sorted or merged; relative paths are not resolved (use the string paths argument to enable relative path resolving based on the current working directory). | ||
<inputs> | : | org.unix4j.io.Input... | The inputs to be sorted or merged. | ||
<comparator> | : | java.util.Comparator<? super org.unix4j.line.Line> | The comparator to use for the line comparisons. | ||
<args> | : | String... | String arguments defining the options and operands for the command. Options can be specified by acronym (with a leading dash "-") or by long name (with two leading dashes "--"). Operands other than the default "--paths" operand have to be prefixed with the operand name (e.g. "--comparator" for a subsequent comparator operand value). | ||
<options> | : | SortOptions | The options for the sort command. |
Modifier and Type | Class and Description |
---|---|
static interface |
Sort.Interface<R>
Interface defining all method signatures for the "sort" command.
|
Modifier and Type | Field and Description |
---|---|
static SortFactory |
Factory
Singleton
factory instance for the "sort" command. |
static String |
NAME
The "sort" command name.
|
static SortOptionSets |
Options
|
public static final String NAME
public static final SortOptionSets Options
c
, m
, u
, b
, d
, f
, n
, g
, h
, M
, V
, r
.
-c | --check | Checks that the single input file is ordered as specified by the arguments and the collating sequence of the current locale. No output is produced; only the exit code is affected. | |||
-m | --merge | Merge only; the input file are assumed to be already sorted. | |||
-u | --unique | Unique: suppress all but one in each set of lines having equal keys.
If used with the -c option, checks that there are no lines
with duplicate keys, in addition to checking that the input file is
sorted. | |||
-b | --ignoreLeadingBlanks | Ignore leading blanks. (This option is ignored if a comparator operand is present). | |||
-d | --dictionaryOrder | Consider only blanks and alphanumeric characters. (This option is ignored if a comparator operand is present). | |||
-f | --ignoreCase | Consider all lowercase characters that have uppercase equivalents to be the uppercase equivalent for the purposes of comparison. (This option is ignored if a comparator operand is present). | |||
-n | --numericSort | Sort numerically; the number begins each line and consists of
optional blanks, an optional minus sign, and zero or more digits
possibly separated by thousands separators, optionally followed by a
decimal-point character and zero or more digits. An empty number is
treated as '0'. The current local specifies the decimal-point
character and thousands separator.
Comparison is exact; there is no rounding error.
Neither a leading '+' nor exponential notation is recognized. To
compare such strings numerically, use the
(This option is ignored if a comparator operand is present). | |||
-g | --generalNumericSort | Sort numerically, using the standard Double.parseDouble(String)
function to convert a trimmed line to a double-precision floating
point number. This allows floating point numbers to be specified in
scientific notation, like 1.0e-34 and 10e100.
Uses the following collating sequence: Lines that cannot be parsed because they do not represent valid double values (in alpha-numeric order); "-Infinity"; finite numbers in ascending numeric order (with -0 < +0); "Infinity"; "NaN".
This option is usually slower than (This option is ignored if a comparator operand is present). | |||
-h | --humanNumericSort | Sort numerically, first by numeric sign (negative, zero, or
positive); then by SI suffix (either empty, or 'k' or 'K', or one
of 'MGTPEZY', in that order); and finally by numeric value. For
example, '1023M' sorts before '1G' because 'M' (mega) precedes 'G'
(giga) as an SI suffix.
This option sorts values that are consistently scaled to the nearest
suffix, regardless of whether suffixes denote powers of 1000 or
1024, and it therefore sorts the output of any single invocation of
the
The syntax for numbers is the same as for the
(This option is ignored if a comparator operand is present). | |||
-M | --monthSort | An initial string, consisting of any amount of blanks, followed by a month name abbreviation, is folded to UPPER case and compared in the order: (unknown) < 'JAN' < ... < 'DEC'. The current locale determines the month spellings. | |||
-V | --versionSort | Sort by version name and number. It behaves like a standard sort,
except that each sequence of decimal digits is treated numerically
as an index/version number.
(This option is ignored if a comparator operand is present). | |||
-r | --reverse | Reverse the sense of comparisons. |
public static final SortFactory Factory
factory
instance for the "sort" command.Copyright © 2024. All rights reserved.