Linux Command-sort
Name: sort
Location:/Usr/bin/sort
Permission:All users
Usage:Sort [OPTION]... [FILE]...
Sort [OPTION]... -- files0-from = F
Option:
-B -- ignore-leading-blanks: ignore the leading space.
-F -- ignore-case fold lower case to upper case characters ignore uppercase and lowercase letters
-M -- month-sort compare (unknown) <'Jan '<... <'dec' is sorted by month name.
-N -- numeric-sort compare according to string numerical values are sorted in plain numbers (sorted by text by default)
$ Cat a11325143 $ sort a11133245 $ sort-n a13451132-u -- unique contains only one row of Data $ cat a13513 $ sort-u a135
-T -- field-separator = SEP use SEP instead of non-blank to blank transition specifies the delimiter. By default, TAB is used as the delimiter.
-K -- key = POS1 [, POS2] start a key at POS1 (origin 1), end it at POS2 (default end of line). See POS syntax below
Specify the sorting Interval
Sort the first field with the colon ":" As the Separator
Head/etc/passwdroot: x: 0: 0: root:/bin/bashdaemon: x: 1: 1: daemon:/usr/sbin:/bin/shbin: x: 2: 2: bin:/bin/shsys: x: 3: 3: sys:/dev:/bin/shsync: x: 4: 65534: sync: /bin:/bin/syncgames: x: 5: 60: games:/usr/games:/bin/shman: x: 6: 12: man: /var/cache/man:/bin/shlp: x: 7: 7: lp:/var/spool/lpd:/bin/shmail: x: 8: 8: mail: /var/mail:/bin/shnews: x: 9: 9: news:/var/spool/news: /bin/sh $ head/etc/passwd | sort-t ":"-k 1bin: x: 2: 2: bin:/bin/shdaemon: x: 1: 1: daemon:/usr/sbin:/bin/shgames: x: 5: 60: games:/usr/games:/bin/shlp: x: 7: 7: lp:/var/spool/lpd:/bin/shmail: x: 8: 8: mail:/var/mail:/bin/shman: x: 6: 12: man: /var/cache/man:/bin/shnews: x: 9: news:/var/spool/news:/bin/shroot: x: 0: 0: root: /root:/bin/bashsync: x: 4: 65534: sync:/bin/syncsys: x: 3: sys:/dev: /bin/sh the following example shows the importance of-n $ cat apa: 11: asa: 32: capp: 5: bstort: 1: dpear: 4: aahello: 3: f $ cat a | sort-t ":"-k 2 PA: 11: astort: 1: dsa: 32: chello: 3: fpear: 4: aaapp: 5: B $ cat a | sort-t ":"-k 2-n stort: 1: dhello: 3: fpear: 4: aaapp: 5: bpa: 11: asa: 32: c