Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


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

Linux sort uniq 大约 347 字

有文本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

阅读 4402 · 发布于 2019-08-26

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

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

扫描二维码关注我
昵称:
随便看看 换一批