linux 中输出两个比较文件中所有唯一项中各自的唯一项

 

001、测试文件

[root@PC1 test2]# ls
a.txt  b.txt
[root@PC1 test2]# cat a.txt        ## 测试文件
a
b
k
c
j
[root@PC1 test2]# cat b.txt        ## 测试文件
a
x
b
y
c

 

 

002、输出两个文件合并后的唯一项

[root@PC1 test2]# ls
a.txt  b.txt
[root@PC1 test2]# cat a.txt
a
b
k
c
j
[root@PC1 test2]# cat b.txt
a
x
b
y
c
[root@PC1 test2]# cat a.txt b.txt | sort | uniq -u      ## 输出两个文件合并后的唯一项
j
k
x
y

 

 

003、输出唯一项中a.txt中的唯一项

[root@PC1 test2]# ls
a.txt  b.txt
[root@PC1 test2]# cat a.txt
a
b
k
c
j
[root@PC1 test2]# cat b.txt
a
x
b
y
c
[root@PC1 test2]# cat a.txt b.txt b.txt | sort | uniq -u    ## 输出唯一项中a.txt中的唯一项
j
k

 

 

004、输出两个文件唯一项中b.txt中的唯一项

[root@PC1 test2]# ls
a.txt  b.txt
[root@PC1 test2]# cat a.txt
a
b
k
c
j
[root@PC1 test2]# cat b.txt
a
x
b
y
c
[root@PC1 test2]# cat a.txt a.txt b.txt | sort | uniq -u            ## 输出两个文件唯一项中b.txt中的唯一项
x
y

 

posted @ 2023-01-01 21:39  小鲨鱼2018  阅读(36)  评论(0编辑  收藏  举报