婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > linux下的刪除重復(fù)行命令uniq詳細(xì)介紹和實(shí)例

linux下的刪除重復(fù)行命令uniq詳細(xì)介紹和實(shí)例

熱門標(biāo)簽:江西意向度高的羿智云外呼系統(tǒng) 濟(jì)南智能語音電銷機(jī)器人加盟 河南語音電銷機(jī)器人加盟公司 易聯(lián)系統(tǒng)外呼營銷來回呼 如何找電銷機(jī)器人 無錫真人電銷機(jī)器人供應(yīng)商 抖音商家地圖標(biāo)注入駐店 無錫ai智能語音電銷機(jī)器人廠家 電銷機(jī)器人怎么打卡

一,uniq干什么用的

文本中的重復(fù)行,基本上不是我們所要的,所以就要去除掉。linux下有其他命令可以去除重復(fù)行,但是我覺得uniq還是比較方便的一個。使用uniq的時候要注意以下二點(diǎn)
1,對文本操作時,它一般會和sort命令進(jìn)行組合使用,因?yàn)閡niq 不會檢查重復(fù)的行,除非它們是相鄰的行。如果您想先對輸入排序,使用sort -u。
2,對文本操作時,若域中為先空字符(通常包括空格以及制表符),然后非空字符,域中字符前的空字符將被跳過

二,uniq參數(shù)說明


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost ~]$ uniq --help
用法:uniq [選項(xiàng)]... [文件]
從輸入文件或者標(biāo)準(zhǔn)輸入中篩選相鄰的匹配行并寫入到輸出文件或標(biāo)準(zhǔn)輸出。/p> p>不附加任何選項(xiàng)時匹配行將在首次出現(xiàn)處被合并。/p> p>長選項(xiàng)必須使用的參數(shù)對于短選項(xiàng)時也是必需使用的。
-c, --count //在每行前加上表示相應(yīng)行目出現(xiàn)次數(shù)的前綴編號
-d, --repeated //只輸出重復(fù)的行
-D, --all-repeated //只輸出重復(fù)的行,不過有幾行輸出幾行
-f, --skip-fields=N //-f 忽略的段數(shù),-f 1 忽略第一段
-i, --ignore-case //不區(qū)分大小寫
-s, --skip-chars=N //根-f有點(diǎn)像,不過-s是忽略,后面多少個字符 -s 5就忽略后面5個字符
-u, --unique //去除重復(fù)的后,全部顯示出來,根mysql的distinct功能上有點(diǎn)像
-z, --zero-terminated end lines with 0 byte, not newline
-w, --check-chars=N //對每行第N 個字符以后的內(nèi)容不作對照
--help //顯示此幫助信息并退出
--version //顯示版本信息并退出

其中-z不知道有什么用

三,測試文本文件uniqtest


復(fù)制代碼
代碼如下:

this is a test
this is a test
this is a test
i am tank
i love tank
i love tank
this is a test
whom have a try
WhoM have a try
you have a try
i want to abroad
those are good men
we are good men

四,實(shí)例詳解


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -c uniqtest
3 this is a test
1 i am tank
2 i love tank
1 this is a test //和第一行是重復(fù)的
1 whom have a try
1 WhoM have a try
1 you have a try
1 i want to abroad
1 those are good men
1 we are good men

從上例子中我們可以看出,uniq的一個特性,檢查重復(fù)行的時候,只會檢查相鄰的行。重復(fù)數(shù)據(jù),肯定有很多不是相鄰在一起的。


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ sort uniqtest |uniq -c
1 WhoM have a try
1 i am tank
2 i love tank
1 i want to abroad
4 this is a test
1 those are good men
1 we are good men
1 whom have a try
1 you have a try


這樣就可以解決上個例子中提到的問題


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -d -c uniqtest
3 this is a test
2 i love tank

uniq -d 只顯示重復(fù)的行


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -D uniqtest
this is a test
this is a test
this is a test
i love tank
i love tank

uniq -D 只顯示重復(fù)的行,并且把重復(fù)幾行都顯示出來。他不能和-c一起使用


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -f 1 -c uniqtest
3 this is a test
1 i am tank
2 i love tank
1 this is a test
2 whom have a try
1 you have a try
1 i want to abroad
2 those are good men //只有一行,顯示二行

在這里those只有一行,顯示的卻是重復(fù)了,這是因?yàn)椋?f 1 忽略了第一列,檢查重復(fù)從第二字段開始的。


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -i -c uniqtest
3 this is a test
1 i am tank
2 i love tank
1 this is a test
2 whom have a try //一個大寫,一個小寫
1 you have a try
1 i want to abroad
1 those are good men
1 we are good men

檢查的時候,不區(qū)分大小寫


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -s 4 -c uniqtest
3 this is a test
1 i am tank
2 i love tank
1 this is a test
3 whom have a try //根上一個例子有什么不同
1 i want to abroad
1 those are good men
1 we are good men


檢查的時候,不考慮前4個字符,這樣whom have a try 就和 you have a try 就一樣了。


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -u uniqtest
i am tank
this is a test
whom have a try
WhoM have a try
you have a try
i want to abroad
those are good men
we are good men

去重復(fù)的項(xiàng),然后全部顯示出來


復(fù)制代碼
代碼如下:

[zhangy@BlackGhost mytest]$ uniq -w 2 -c uniqtest
3 this is a test
3 i am tank
1 this is a test
1 whom have a try
1 WhoM have a try
1 you have a try
1 i want to abroad
1 those are good men
1 we are good men

對每行第2個字符以后的內(nèi)容不作檢查,所以i am tank 根 i love tank就一樣了。

標(biāo)簽:保定 銅陵 衢州 運(yùn)城 潛江 山南 麗水 新余

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《linux下的刪除重復(fù)行命令uniq詳細(xì)介紹和實(shí)例》,本文關(guān)鍵詞  linux,下,的,刪除,重復(fù),行,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《linux下的刪除重復(fù)行命令uniq詳細(xì)介紹和實(shí)例》相關(guān)的同類信息!
  • 本頁收集關(guān)于linux下的刪除重復(fù)行命令uniq詳細(xì)介紹和實(shí)例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 台中市| 巴马| 高要市| 兴业县| 沙湾县| 历史| 牡丹江市| 桂阳县| 盘锦市| 北宁市| 屏边| 饶阳县| 陇西县| 万山特区| 彩票| 济阳县| 吉安县| 玛沁县| 习水县| 会东县| 庄浪县| 章丘市| 临漳县| 泊头市| 八宿县| 凉城县| 高碑店市| 琼中| 井研县| 彭泽县| 亳州市| 霞浦县| 望谟县| 固始县| 武清区| 太仆寺旗| 洪湖市| 资中县| 旬阳县| 中方县| 万州区|