如何解决Linux:为什么我无法显示这两个文件之间的不同行?
我想比较两个文件并显示这两个文件之间不同的行。我已经尝试了一些方法来做到这一点,但我无法做到...
我有第一个文件:
frvmx0000423
ansible-test-relay-do-not-delete
frvmx0000434
frvmt0003036
frvmx0000661
rhel6918111243
frvmx0000416
frvmt0003040
mcds-test-303
jmt201
fb-demo5
frvmx0000635
cb003
rhel7511130951
rhel7511130956
vlpchh08
mcds-test-301
frvmx0000576
frvmx0000683
frvmx0000654
frvmx0000685
frvmx0000446
vlplin01
frvmx0000687
rhel69611917
frvmx0000622
rhel7511161022
vlpijl03
vlpedu03
第二个文件:
frvmx0000683
frvmx0000576
ansible-test-relay-do-not-delete
vlpedu03
frvmx0000687
frvmx0000685
frvmx0000654
frvmt0003299
mcds-test-301
cb003
mcds-test-303
FRVMT0003040
cb004
frvmx0000661
frvmt0003036
我想要这个输出,它是文件之间不同的行:
frvmx0000423
frvmx0000434
rhel6918111243
frvmx0000416
jmt201
fb-demo5
frvmx0000635
rhel7511130951
rhel7511130956
vlpchh08
frvmx0000446
vlplin01
rhel69611917
frvmx0000622
rhel7511161022
vlpijl03
但是当我尝试使用 diff 命令时:
diff --suppress-common-lines file1 file2
输出是:
1,15c1,29
< frvmx0000683
< frvmx0000576
< ansible-test-relay-do-not-delete
< vlpedu03
< frvmx0000687
< frvmx0000685
< frvmx0000654
< frvmt0003299
< mcds-test-301
< cb003
< mcds-test-303
< FRVMT0003040
< cb004
< frvmx0000661
< frvmt0003036
---
> frvmx0000423
> ansible-test-relay-do-not-delete
> frvmx0000434
> frvmt0003036
> frvmx0000661
> rhel6918111243
> frvmx0000416
> frvmt0003040
> mcds-test-303
> jmt201
> fb-demo5
> frvmx0000635
> cb003
> rhel7511130951
> rhel7511130956
> vlpchh08
> mcds-test-301
> frvmx0000576
> frvmx0000683
> frvmx0000654
> frvmx0000685
> frvmx0000446
> vlplin01
> frvmx0000687
> rhel69611917
> frvmx0000622
> rhel7511161022
> vlpijl03
> vlpedu03
如果我尝试使用 sort
和 uniq
:
cat postman_list vcenter_list | sort | uniq -u
输出是:
FRVMT0003040
ansible-test-relay-do-not-delete
ansible-test-relay-do-not-delete
cb003
cb003
cb004
fb-demo5
frvmt0003036
frvmt0003036
frvmt0003040
frvmt0003299
frvmx0000416
frvmx0000423
frvmx0000434
frvmx0000446
frvmx0000576
frvmx0000576
frvmx0000622
frvmx0000635
frvmx0000654
frvmx0000654
frvmx0000661
frvmx0000661
frvmx0000683
frvmx0000683
frvmx0000685
frvmx0000685
frvmx0000687
frvmx0000687
jmt201
mcds-test-301
mcds-test-301
mcds-test-303
mcds-test-303
rhel6918111243
rhel69611917
rhel7511130951
rhel7511130956
rhel7511161022
vlpchh08
vlpedu03
vlpedu03
vlpijl03
vlplin01
有人教我怎么做吗?
解决方法
我对你的定义有点困惑
lines that are differents between the files
因为显示的预期输出看起来像 lines unique to file1
。
如果是这样,请尝试:
comm -2 -3 <(sort file1) <(sort file2)
输出:
fb-demo5
frvmt0003040
frvmx0000416
frvmx0000423
frvmx0000434
frvmx0000446
frvmx0000622
frvmx0000635
jmt201
rhel6918111243
rhel69611917
rhel7511130951
rhel7511130956
rhel7511161022
vlpchh08
vlpijl03
vlplin01
相反,如果您想打印两者“file1 独有的行”和
“文件 2 独有的行”,这将是常见的解释
different lines
,请尝试:
comm -3 --output-delimiter= <(sort file1) <(sort file2)
输出:
FRVMT0003040
cb004
fb-demo5
frvmt0003040
frvmt0003299
frvmx0000416
frvmx0000423
frvmx0000434
frvmx0000446
frvmx0000622
frvmx0000635
jmt201
rhel6918111243
rhel69611917
rhel7511130951
rhel7511130956
rhel7511161022
vlpchh08
vlpijl03
vlplin01
,
将 grep 与 -f(来自文件的模式列表)和 -v(反向匹配)一起使用
grep -v -f file2 file1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。