String interception cut、 Sort sort、 duplicate removal uniq、 Replace tr、 Character statistics wc



Sort -sort


sort [ Options ] [ file ]
Nothing , Sort by initials by default , By default, spaces are used as separators .
-t Specify the separator , By default, spaces are used as separators .
-k Specify the columns .
[[email protected] ~]# cat sort.log |sort -t'.' -k2
218.65.30.124 17163
218.65.30.126 17163
218.65.30.25 68652
218.65.30.53 34326
218.65.30.61 17163
112.85.42.103 18065
112.85.42.99 17164
218.87.109.150 17163
218.87.109.151 17163
218.87.109.154 21201
-n In Arabic numerals , Sort by the first character of the letter by default .
-r reverse
[[email protected] ~]# cat sort.log |sort -t' ' -k2 -nr
218.65.30.25 68652
218.65.30.53 34326
218.87.109.154 21201
112.85.42.103 18065
112.85.42.99 17164
218.87.109.151 17163
218.87.109.150 17163
218.65.30.61 17163
218.65.30.126 17163
218.65.30.124 17163


duplicate removal -uniq


uniq  Options   file
effect : duplicate removal , We can only duplicate the same content adjacent to each other .
-c Statistics
[[email protected] ~]# cat sort1.txt |sort|uniq -c
      2 192.168.0.151
      1 192.168.0.152
      2 192.168.0.153
      1 192.168.1.1
      1 192.168.1.10
      1 192.168.1.11


Intercept character -cut


 usage : cut [ Options ] [ file ]
-d Specify the separator
-f Designated area
[[email protected] ~]# cut -d':' -f1,7 /etc/passwd
root:/bin/bash
bin:/sbin/nologin
daemon:/sbin/nologin
adm:/sbin/nologin
-c Take character
[[email protected] ~]# echo 123456 |cut -c 3-5
345


Character substitution -tr


tr  Old characters   New character
[[email protected] ~]# echo 123a123b123c|tr 'a' 'b'
123b123b123c


Statistical orders -wc


wc  file
[[email protected] tmp]# wc /etc/services 
 11176  61033 670293 /etc/services
-c Count by bytes
[[email protected] ~]# wc -c /etc/services 
670293 /etc/services
-w According to the number of words
[[email protected] ~]# wc -w /etc/services 
61033 /etc/services
-l The statistical number of rows
[[email protected] ~]# wc -l /etc/services 
11176 /etc/services