In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, Xiaobian will bring you about how the sort command is used in Linux. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
Name: sort
Location: /usr/bin/sort
Permission: All Users
Usage: sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F
Options:
-b --ignore-leading-blanks Ignore leading spaces
-f --ignore-case fold lower case to upper case characters Ignore case of letters
-M --month-sort compare (unknown) < `JAN' < ... < `DEC'Sorted by month name
-n --numeric-sort compare according to string numerical value (default sort by text type)
The code is as follows:
$ cat a
11
32
5
1
4
3
$ sort a
1
11
3
32
4
5
$ sort -n a
1
3
4
5
11
32
-u --unique In the same data, only one row appears
$ cat a
1
3
5
1
3
$ sort -u a
1
3
5
-t --field-separator=SEP use SEP instead of non-blank to blank transition Specify separator, default TAB as separator
-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 sorted interval
Sort first field delimited by colon ":"
head /etc/passwdroot:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/bin/shbin:x:2:2:bin:/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:/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:9:news:/var/spool/news:/bin/shroot:x:0:0:root:/root:/bin/bashsync:x:4:65534:sync:/bin:/bin/syncsys:x:3: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 The above is how the sort command shared by Xiaobian is used in Linux. If you happen to have similar doubts, you may wish to refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.