Sort (Unix)

Sort (Unix)

Sort is a standard Unix command line program that prints the lines of its input or concatenation of all files listed in its argument list in sorted order. Sorting is done based on one or more sort keys extracted from each line of input. By default, the entire input is taken as sort key. Blank space is taken used as default field separator.The -r flag will reverse the sort order.

Examples

Sort the current directory by file size

$ls -s | sort -n 96 Nov1.txt 128 _arch_backup.lst 128 _arch_backup.lst.tmp 1708 NMON

Sort a file in alpha order

$ cat "phonebook" Smith, Brett 555-4321 Doe, John 555-1234 Doe, Jane 555-3214 Avery, Cory 555-4321 Fogarty, Suzie 555-2314 $ sort "phonebook" Avery, Cory 555-4321 Doe, Jane 555-3214 Doe, John 555-1234 Fogarty, Suzie 555-2314 Smith, Brett 555-4321

Sort by number

The -n option makes the program sort according to numerical value: $ du /bin/* | sort -n 4 /bin/domainname 24 /bin/ls 102 /bin/sh 304 /bin/csh

In old versions of sort, the +1 option made the program sort using the second column of data (+2 for the third, etc.). This is no longer supported, and instead the -k option can be used to do the same thing (note: "-k 2" for the second column): $ cat "zipcode" Adam 12345 Bob 34567 Joe 56789 Sam 45678 Wendy 23456 $ sort -nk 2 "zipcode" Adam 12345 Wendy 23456 Bob 34567 Sam 45678 Joe 56789

Sorting a pipe delimited file

$ sort -t'|' -k2 "zipcode" Adam|12345 Wendy|23456 Bob|34567 Sam|45678 Joe|56789

Sort in reverse

The -r option just reverses the order of the sort: $ sort -nrk 2 "zipcode" Joe 56789 Sam 45678 Bob 34567 Wendy 23456 Adam 12345

ee also

*Collation
*List of Unix programs

External links

* [http://www.linuxmanpages.com/man1/sort.1.php] The program's manpage
* [http://softpanorama.org/Tools/sort.shtml Softpanorama Unix sort page]
* [http://www.iconv.com/sort.htm Online interface to the sort program]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Sort (Unix) — Pour les articles homonymes, voir sort. sort est une commande POSIX qui permet de trier les lignes de fichiers texte. Par défaut, sort affiche l ensemble des lignes des fichiers qu on lui passe en paramètre triées par ordre croissant de la table… …   Wikipédia en Français

  • sort (Unix) — sort es una utilidad de la línea de comandos del sistema operativo Unix. Funciona de la siguiente manera: toma los archivos que figuran en su lista de argumentos y ordena sus líneas. La ordenación se realiza sobre la base de una o más claves… …   Wikipedia Español

  • sort (Unix) — Pour les articles homonymes, voir sort. sort est une commande POSIX qui permet de trier des fichiers ou leurs contenus. Par défaut, sort affiche l ensemble des lignes des fichiers qu on lui passe en paramètre triées par ordre croissant de la… …   Wikipédia en Français

  • sort — UNIX‐утилита, выводящая сортированное слияние указанных файлов на стандартный вывод с использованием установленной в среде локали. Использование sort [ m][ o output][ bdfinru][ t char][ k keydef]… [file…] sort c [ bdfinru][ t char][ k… …   Википедия

  • Sort — may mean * Sorting, any process of arranging items in sequence or in sets ** In conveyor lines sortage is the term for a checkweigher sorting products. ** Sorting algorithm, a computer process for arranging elements in lists ** Sort (Unix), a… …   Wikipedia

  • Sort — UNIX‐утилита, выводящая сортированное слияние указанных файлов на стандартный вывод с использованием установленной в среде локали. Использование sort [ m][ o output][ bdfinru][ t char][ k keydef]… [file…] sort c [ bdfinru][ t char][ k… …   Википедия

  • SORT — steht für Sort (Lleida), eine Kleinstadt in Katalonien Sort (Unix), ein Unix Programm zum Sortieren Sort (Windows), ein Windows Programm zum Sortieren SORT steht als Abkürzung für: Special Operations Response Team, eine Spezialeinheit des US… …   Deutsch Wikipedia

  • Sort — steht für Sort (Lleida), eine Kleinstadt in Katalonien Sort (Unix), ein Unix Programm zum Sortieren Sort (Windows), ein Windows Programm zum Sortieren SORT steht als Abkürzung für: Special Operations Response Team, eine Spezialeinheit des US… …   Deutsch Wikipedia

  • Unix — (marque déposée officiellement comme UNIX, parfois aussi écrit comme Unix avec les petites capitalisations) est le nom d un système d exploitation multitâche et multi utilisateur créé en 1969, conceptuellement ouvert et fondé sur une approche par …   Wikipédia en Français

  • UNIX — UNIX, parfois écrit « Unix », avec des petites capitales, est un système d exploitation multitâche et multi utilisateur créé en 1969, conceptuellement ouvert et fondé sur une approche par laquelle il offre de nombreux petits outils… …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”