Most of the time, we are going to calculate the total number of identical patterns in the data, for example, using last can be used to find the identity of the landing host this month. Can I find out their total number of landings for each user? At this point, you need to sort and calculate commands such as to assist! Below we introduce a few handy sort with statistics commands, first of all is sort order command sort.
[Email protected] ~]#Sort[-fbmnrtuk] [fileor stdin] options and Parameters:-F: Ignores case differences, such as a and a are treated as encodings;-B: Ignore the first whitespace part;-M: Sort by the name of the month, such as JAN, DEC and so on;-N: Sort using "pure number" (by default it is sorted by text type);-r: Reverse sort;-U: YesUniq, in the same data, there is only one row represented;-T: delimiter, the default is to use the [tab] key to separate;-K: An example of a sort by that interval (field): A personal account is recorded in/etc/passwd, please sort the account number. [[Email protected]~]#Cat/etc/passwd|Sortadm:x:3:4: adm:/var/adm:/sbin/nologinapache:x: -: -: apache:/var/www:/sbin/nologinbin:x:1:1: bin:/bin:/sbin/nologindaemon:x:2:2:d aemon:/sbin:/sbin/nologin# is omitted a lot of output ~ by the above data looks,Sortis the default "first" data to sort, # and by default it is sorted by "text" type! So from a start to the last! Example two:/etc/passwdThe content is separated by: I want to sort by the third column, how? [[Email protected]~]#Cat/etc/passwd|Sort-T':'-K3root:x:0:0: root:/root:/bin/bashuucp:x:Ten: -: uucp:/var/spool/uucp:/sbin/nologinoperator:x: One:0: operator:/root:/sbin/nologinbin:x:1:1: bin:/bin:/sbin/nologingames:x: A: -: games:/usr/games:/sbin/nologin# See the output part of the special font? How could this be arranged? Oh! That's right, ~#. If you sort by text type, it would have been like this, want to use a number sort: #Cat/etc/passwd|Sort-T':'-K3-n# that's all right! With that-N to informSortSort By Numbers! Example three: Using Last, the output data is only taken account, and sorted [[email protected]~]# Last|Cut-D' '-f1 |Sort
Sort is also a very common command! Because we often need to compare some information! Give me a second example above. Today, suppose you have a lot of accounts, and you want to know which number the largest user ID is now! Oh! Use sort to get an answer! Of course, its use is more than this! If you have time, you might as well play!
Reference:http://vbird.dic.ksu.edu.tw/linux_basic/0320bash.php#sort