1. 程式人生 > >文本處理命令--uniq

文本處理命令--uniq

uniq 命令 oot lin test round pytho nbsp repeat

uniq - report or omit repeated lines

報告或刪除重復行。

註:常與sort結合使用,因為uniq可以去除重復的行(重復的行需要是相鄰的)。

[root@www1 ~]# cat test.txt
aaa 111 222        #此行有重復哦
ccc 333 444
aaa 111 222
ggg 555 666
bbb 777 888
eee 999 000        #連續重復行
eee 999 000

[root@www1 ~]# uniq test.txt
aaa 111 222            #沒有去重
ccc 333 444
aaa 111 222
ggg 555 666
bbb 777 888
eee 999 000
[root@www1 ~]# uniq -c test.txt
      1 aaa 111 222            #未計數
      1 ccc 333 444
      1 aaa 111 222
      1 ggg 555 666
      1 bbb 777 888
      2 eee 999 000

[root@www1 ~]# sort test.txt |uniq    #與sort結合使用後,可去除aaa行
aaa 111 222
bbb 777 888
ccc 333 444
eee 999 000
ggg 555 666


文本處理命令--uniq