Opentopia Directory Encyclopedia Tools

Sort (Unix)

Encyclopedia : S : SO : SOR : Sort (Unix)



 

The correct title of this } is }}}. The initial letter is capitalized due to [Naming conventions #Lower case first lettertechnical restrictions].
sort is a standard Unix command line program that prints the lines of its input or concatenation of all files listed in it's argument list in sorted order. The -r flag will reverse the sort order.

Example of sort in action:

$ cat phonebook

Smith, Brett 555-4321 Doe, John 555-1234 Doe, Jane 555-3214 Avery, Cory 555-4321 Fogarty, Suzie 555-2314

$ cat phonebook | sort

Avery, Cory 555-4321 Doe, Jane 555-3214 Doe, John 555-1234 Fogarty, Suzie 555-2314 Smith, Brett 555-4321

The -n option makes the program to sort according to numerical value:
$ du /bin/* | sort -n

4 /bin/domainname 4 /bin/echo 4 /bin/hostname 4 /bin/pwd ... 24 /bin/ls 30 /bin/ps 44 /bin/ed 54 /bin/rmail 80 /bin/pax 102 /bin/sh 304 /bin/csh

The -n +1 option makes the program to sort according to numerical value, using the second column of data:
$ cat zipcode

Adam 12345 Bob 34567 Joe 56789 Sam 45678 Wendy 23456

$ cat zipcode | sort -n +1

Adam 12345 Wendy 23456 Bob 34567 Sam 45678 Joe 56789

The -r option just reverses the order of the sort:
$ cat zipcode | sort -nr +1

Joe 56789 Sam 45678 Bob 34567 Wendy 23456 Adam 12345

See also

External links

Unix command line programs[ view][ talk][ edit] )
File and file system management: cat | chdir/cd | chmod | chown | chgrp | cp | du | df | fdupes | file | fsck | ln | ls | lsof | mkdir | more | mount | mv | pwd | rcp | rm | rmdir | split | touch | tree
Process management: anacron | at | chroot | cron/crontab | kill | nice | ps | sleep | time | timex | top | renice | wait
User Management/Environment: env | finger | id | locale | mesg | passwd | su | sudo | uname | uptime | w | who | write
Text processing: awk | cut | diff | ex | head | iconv | join | less | more | nkf | paste | sed | sort | tail | tr | uniq | wc | xargs
Shell programming: echo | expr | unset Printing: lp
Communications:
inetd | netstat | ping | rlogin | traceroute
Searching:
egrep | fgrep | find | grep | strings
Miscellaneous:
banner | bc | cal | man | uname | wall | yes

 


From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.


Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: