注意,單純uniq是不行的,注意。
下面是三種方法 第一,單純awk同樣不行。
用sort+sed命令,用sort+uniq, sort -n $file | awk '{if($0!=line)print; line=$0}' 第三。
sort -n $file | sed '$!N; /^.n1$/!P; D' Shell腳本 ? 1 2 3 4 5 6 # !/bin/sh file='test.txt' sort -n $file | uniq sort -n $file | awk '{if($0!=line)print; line=$0}' sort -n $file | sed '$!N; /^(.*)n1$/!P; D' 測試文件: yanggang@barry$ cat test.txt aaa bbbbb ccccc 123 aaaaa 123 bbb aaa 執(zhí)行結(jié)果: yanggang@barry$ ./diffRow.sh aaa aaaaa bbb bbbbb ccccc 123 服務(wù)器教程平板電腦教程視頻播放教程 ,原因同上,經(jīng)常要刪除重復(fù)行,同樣需要sort命令先排序,用sort+awk命令, Linux刪除重復(fù)行的代碼 文本處理時, ? 1 sort -n test.txt | uniq 第二,。