比较在bash两个文件 [英] Compare two files in bash
本文介绍了比较在bash两个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文件tmp1.txt和tmp2.txt
tmp1.txt有
I have two files tmp1.txt and tmp2.txt tmp1.txt has
aaa.txt
bbb.txt
ccc.txt
ddd.txt
tmp2.txt有
tmp2.txt has
/tmp/test1/aaa.txt
/tmp/test1/aac.txt
/tmp/test2/bbb.txt
/tmp/test1/ccc.txt
我要检查是否存在tmp2.txt在tmp1.txt文件,如果存在显示它,使其显示类似这样的东西哪一个
I want to check if the files in tmp1.txt exists in tmp2.txt and if it exists display which one it has so it displays something similar to this
aaa.txt: test1
bbb.txt: test2
ccc.txt: test1
感谢
推荐答案
使用 AWK
:
awk -F/ 'FNR==NR {a[$1];next} $NF in a {print $NF ": " $(NF-1)}' tmp1.txt tmp2.txt
aaa.txt: test1
bbb.txt: test2
ccc.txt: test1
这篇关于比较在bash两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文