天天看點

linux檔案合并,去重

(1)兩個檔案的交集,并集

前提條件:每個檔案中不得有重複行

1. 取出兩個檔案的并集(重複的行隻保留一份)

cat file1 file2 | sort | uniq > file3

2. 取出兩個檔案的交集(隻留下同時存在于兩個檔案中的檔案)

cat file1 file2 | sort | uniq -d > file3

3. 删除交集,留下其他的行

cat file1 file2 | sort | uniq -u > file3

(2)兩個檔案合并

一個檔案在上,一個檔案在下

cat file1 file2 > file3

一個檔案在左,一個檔案在右

paste file1 file2 > file3

(3)一個檔案去掉重複的行

sort file |uniq