Sort command
Sort : Text sort, just the sort of display files, without affecting the order of source files, is based on assii codethe word Fu Shen order to arrange. -N: Installation values are arranged from small to large, ascending by default. - R: Descending order * * * *-T: Specifies the field delimiter, which means separating fields by dot (similar to Awk-f, take fields with the-D of $1,$2 or cut, take field F numbers)- K: Specifies the number of characters in the column or columns, equivalent to the-F2 in the cut-d "delimiter"-u: output only one line for the same line * * * *- F: Ignore character caseExample: Remove "A-Z" subtitles and sort
[[email protected]-server test]# cat test.txt
10.0.0.9 a
10.0.0.8 k
10.0.0.7 f
10.0.0.7 n
10.0.0.8 c
10.0.0.8 z
10.0.0.9 o
Method 1:
[[email protected]-server test]# cut -d " "-f2 test.txt|sort -n ##-d后面跟分隔符为空格,-f指定第2列,然后通过sort排序
a
c
f
k
n
o
z
Method 2:
[[email protected]-server test]# awk -F ‘ ‘‘{print $2}‘ test.txt|sort -n
a
c
f
k
n
o
z
Method 3: The delimiter default is a space, so-t can be omitted.
[[email protected]-server test]# sort -t " "-k2 test.txt
10.0.0.9 a
10.0.0.8 c
10.0.0.7 f
10.0.0.8 k
10.0.0.7 n
10.0.0.9 o
10.0.0.8 z
[[email protected]-server test]#
Can be simplified to:
[[email protected]-server test]# sort -k2 test.txt
10.0.0.9 a
10.0.0.8 c
10.0.0.7 f
10.0.0.8 k
10.0.0.7 n
10.0.0.9 o
10.0.0.8 z
Example 2: The implementation of the IP address, sorted in reverse order sorting method:
2.sort Sort Command explanation