Linux-uniq和wc

7.Shell

本章同步視頻:https://edu.51cto.com/sd/e4874

2.uniq - report or omit repeated lines

(1)語法

[dmtsai@study ~]$ uniq [-ic]

選項與參數:

-i:忽略大小寫字符的不同;

-c  :進行計數

(2)用法

[root@localhost tmp]# last|cut -d " " -f 1 >last

[root@localhost tmp]# cat last

root

root

(unknown

reboot

root

root

root

(unknown

root

root

root

(unknown

root

root

root

(unknown

reboot

root

root

root

root

(unknown

reboot

 

wtmp

[root@localhost tmp]# uniq last

root         #不帶任何參數,去掉連續重複的行

(unknown

reboot

root

(unknown

root

(unknown

root

(unknown

reboot

root

(unknown

reboot

 

wtmp

[root@localhost tmp]# uniq -c last

      2 root        #統計重複的次數

      1 (unknown

      1 reboot

      3 root

      1 (unknown

      3 root

      1 (unknown

      3 root

      1 (unknown

      1 reboot

      4 root

      1 (unknown

      1 reboot

      1

      1 wtmp

[root@localhost tmp]# uniq -d last

root      #只顯示重複的行

root

root

root

root

[root@localhost tmp]# uniq -u last

(unknown      #只顯示不重複的行

reboot

(unknown

(unknown

(unknown

reboot

(unknown

reboot

 

wtmp

[root@localhost tmp]# sort last |uniq -c

      1                   #排序後統計重複的行

      3 reboot

     15 root

      5 (unknown

      1 wtmp

#uniq 不會檢查重複的行,除非它們是相鄰的行。

3.wc - print newline, word, and byte counts for each file

(1)語法

[dmtsai@study ~]$ wc [-lwm]

選項與參數:

-l  :僅列出行;

-w  :僅列出多少字(英文單字);

-m  :多少字符;

(2)用法

[root@localhost tmp]# cat wc.file

google 110 5140

baidu 100 532

guge 50 3900

sohu 100 4500

[root@localhost tmp]# wc wc.file

 4 12 57 wc.file    #統計行、單詞和字節數

[root@localhost tmp]# wc -l wc.file

4 wc.file    # 統計行數

[root@localhost tmp]# wc -c wc.file

57 wc.file    #統計字節數

[root@localhost tmp]# wc -w wc.file

12 wc.file     #統計單詞數

[root@localhost tmp]# wc -m wc.file

57 wc.file     #統計字符數

本章同步視頻:https://edu.51cto.com/sd/e4874


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章