檢視sort和uniq去除重複行的區別
uniq命令選項及其意義sort -t: -k7 -u /etc/passwd //去除passwd檔案中域7重複的行
cat /etc/passwd | uniq //去除passwd檔案中域7重複的行
區別1:
sort 可以對指定的域進行排序並且去除重複行
uniq 則不可以對某個相同的域進行去除,只能去除記錄相同的行
區別2:
sort 在排序之後進行去除,排序之後相同的記錄都連續排序在一起
uniq 去除重複行時只能對連續重複的記錄進行去除,而不連續的則無法去除
uniq命令示例:-c #列印每行在文字中重複出現的次數
-d #只顯示有重複的記錄,每個重覆記錄只出現一次
-u #只顯示沒有重複的記錄
sort 和 uniq 結合的命令列印出test文字中每行重複出現的次數
#uniq
-c test
只列印出test文字中重複的行
#uniq
-d test
只列印出test文字中不重複的行
#uniq
-u test
列印出test文字中重複的行出現的次數
#uniq
-cd test
列印出test文字中不重複的行出現的次數
#uniq
-cu test
統計出乙個檔案內每種單詞出現的次數
count=1
err1=55
err2=56
#if檢測用法是否錯誤
if [ $#
-ne$count ]
then
echo
"usage: script file"
exit
$err1
fi#if檢測是否對檔案進行統計
if [ ! -f $! ]
then
echo
"file $1 not does found"
exit
$err2
fisort $1 | uniq -c | sort -nr #將檔案進行排序,然後去除重複並統計行個數,最後按照數字從大到小輸出
shell基礎 uniq命令
uniq命令常見選項 去除重複行 u 顯示不重複的行 d 顯示有重複的行 c 列印每一行重複的次數 測試文字內容如下 cat 4.txt 111111 2222 2222 3333 3333 4444 1 uniq cat 4.txt uniq 去重複行 1112222 3333 4444 要注意!...
Shell之sort與uniq命令簡介
一 sort命令使用 1.指定按數字排序 root topinsight sort cat file1 paixu 4 hebing 1 weiyi 2 chongfu 3 root topinsight sort sort n file1 chongfu 3 hebing 1 paixu 4 we...
Linux基礎 uniq命令總結
blog 個人本文只總結一些常用的用法,更詳細的說明見man uniq和uniq help。目錄uniq命令主要用於去重。需要注意的是,不相鄰的行不算重複值。usage uniq option input output option 說明 c 統計出現的次數 d只顯示被計算為重複的行 d顯示所有被計...