天天看點

Linux下檔案去重

有多個檔案,每個檔案都有交集。 現在要将每個檔案去重。

這裡使用到3個指令:cat、sort、uniq

cat檢視檔案内容

sort排序

uniq去重

1. 取幾個檔案的并集

    cat fileA fileB fileC | sort | uniq

➜  test cat test1
a1
a2
a3
a1
➜  test sort test1
a1
a1
a2
a3
➜  test sort test1 | uniq
a1
a2
a3
           

2. 取幾個檔案的交集

    cat fileA fileB fileC | sort | uniq -d

➜  test sort test1 | uniq -d
a1
           

3. 取幾個檔案不重複的部分

    cat fileA fileB fileC | sort | uniq -u

➜  test sort test1 | uniq -d
a1
           

繼續閱讀