Friday, May 14, 2010

Linux Sort Command Sorting Text Ascending Order Descanting Order

Sort >command Linux is used to sort text data. Sort command is often used with pipes symbol.
BEFORE SORTING
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
AFTER SORTING
[root@localhost ~]# grep bash /etc/passwd | sort
ananth:x:500:500:ananth:/home/ananth:/bin/bash
kumar:x:502:502::/home/kumar:/bin/bash
root:x:0:0:root:/root:/bin/bash
user12:x:503:503::/home/user12:/bin/bash
user1:x:501:501::/home/user1:/bin/bash
user2:x:504:504::/home/user2:/bin/bash
option
-r perform reverse sort with there command sort in Linux
-n perform a numeric sort
-u removes duplicate line in output

0 comments:

Flag counter

free counters