Contenues dansTrouver plus de documentationRessources d'assistance comprises | Télécharger cet ouvrage au format PDF (5130 Ko)
sort(1)NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | USAGE | EXAMPLES | ENVIRONMENT VARIABLES | EXIT STATUS | FILES | ATTRIBUTES | SEE ALSO | DIAGNOSTICS | NOTES NAME
SYNOPSIS
/usr/xpg4/bin/sort [-bcdfimMnru] [-k keydef] [-o output] [-S kmem] [-t char] [-T directory] [-y [kmem]] [-z recsz] [+pos1 [-pos2]] [file…] DESCRIPTIONThe sort command sorts lines of all the named files together and writes the result on the standard output. Comparisons are based on one or more sort keys extracted from each line of input. By default, there is one sort key, the entire input line. Lines are ordered according to the collating sequence of the current locale. OPTIONS
The following options alter the default behavior: /usr/bin/sort/usr/xpg4/bin/sortOrdering OptionsThe default sort order depends on the value of LC_COLLATE. If LC_COLLATE is set to C, sorting will be in ASCII order. If LC_COLLATE is set to en_US, sorting is case insensitive except when the two strings are otherwise equal and one has an uppercase letter earlier than the other. Other locales will have other sort orders. The following options override the default ordering rules. When ordering options appear independent of any key field specifications, the requested field ordering rules are applied globally to all sort keys. When attached to a specific key (see Sort Key Options), the specified ordering options override all global ordering options for that key. In the obsolescent forms, if one or more of these options follows a +pos1 option, it will affect only the key field specified by that preceding option. Field Separator OptionsThe treatment of field separators can be altered using the following options: Sort Key OptionsSort keys can be specified using the options: OPERANDS
The following operand is supported: USAGESee largefile(5) for the description of the behavior of sort when encountering files greater than or equal to 2 Gbyte ( 231 bytes). EXAMPLESIn the following examples, first the preferred and then the obsolete way of specifying sort keys are given as an aid to understanding the relationship between the two forms. Example 1 Sorting with the second field as a sort keyEither of the following commands sorts the contents of infile with the second field as the sort key:
Example 2 Sorting in reverse orderEither of the following commands sorts, in reverse order, the contents of infile1 and infile2, placing the output in outfile and using the second character of the second field as the sort key (assuming that the first character of the second field is the field separator):
Example 3 Sorting using a specified character in one of the filesEither of the following commands sorts the contents of infile1 and infile2 using the second non-blank character of the second field as the sort key:
Example 4 Sorting by numeric user IDEither of the following commands prints the passwd(4) file (user database) sorted by the numeric user ID (the third colon-separated field):
Example 5 Printing sorted lines excluding lines that duplicate a fieldEither of the following commands prints the lines of the already sorted file infile, suppressing all but one occurrence of lines having the same third field:
Example 6 Sorting by host IP addressEither of the following commands prints the hosts(4) file (IPv4 hosts database), sorted by the numeric IP address (the first four numeric fields):
Since '.' is both the field delimiter and, in many locales, the decimal separator, failure to specify both ends of the field will lead to results where the second field is interpreted as a fractional portion of the first, and so forth. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of sort: LANG, LC_ALL, LC_COLLATE, LC_MESSAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: FILESATTRIBUTESSee attributes(5) for descriptions of the following attributes: /usr/bin/sort/usr/xpg4/bin/sortSEE ALSOcomm(1), join(1), uniq(1), nl_langinfo(3C), strftime(3C), hosts(4), passwd(4), attributes(5), environ(5), largefile(5), standards(5) DIAGNOSTICSComments and exits with non-zero status for various trouble conditions (for example, when input lines are too long), and for disorders discovered under the -c option. NOTESWhen the last line of an input file is missing a new-line character, sort appends one, prints a warning message, and continues. sort does not guarantee preservation of relative line ordering on equal keys. One can tune sort performance for a specific scenario using the -S option. However, one should note in particular that sort has greater knowledge of how to use a finite amount of memory for sorting than the virtual memory system. Thus, a sort invoked to request an extremely large amount of memory via the -S option could perform extremely poorly. As noted, certain of the field modifiers (such as -M and -d) cause the interpretation of input data to be done with reference to locale-specific settings. The results of this interpretation can be unexpected if one's expectations are not aligned with the conventions established by the locale. In the case of the month keys, sort does not attempt to compensate for "approximate" month abbreviations. The precise month abbreviations from nl_langinfo(3C) or strftime(3C) are the only ones recognized. For printable or dictionary order, if these concepts are not well-defined by the locale, an empty sort key may be the result, leading to the next key being the significant one for determining the appropriate ordering. NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | USAGE | EXAMPLES | ENVIRONMENT VARIABLES | EXIT STATUS | FILES | ATTRIBUTES | SEE ALSO | DIAGNOSTICS | NOTES |
||||||||||||