Linux 两个文件取并集、交集、差集

Linux sort uniq About 347 words

有文本1.txt,内容如下:

a
b
c
x
y
z

有文本2.txt,内容如下:

a
x
m
n

并集 - uniq

sort 1.txt 2.txt | uniq

输出:

a
b
c
m
n
x
y
z

交集 - uniq -d

sort 1.txt 2.txt | uniq -d

输出:

a
x

差集 - uniq -u

1.txt的差集

sort 1.txt 2.txt 2.txt | uniq -u

输出:

b
c
y
z

2.txt的差集

sort 1.txt 2.txt 1.txt | uniq -u

输出:

m
n

特别注意

需关注两个文件的文件格式,必须一致,否则会出现问题。博主因为两文件格式问题,花费半天时间。

可参考:不同平台文件格式:dos、unix、mac

Views: 4,763 · Posted: 2019-08-26

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh