更新时间:2022-04-16 02:24:24
尝试使用Awk
这是用于此目的的正确工具,
An attempt using Awk
which is the right tool meant for this,
awk -F"/" 'FNR==NR{filearray[$1]=$NF; next }!($1 in filearray){printf "%s has a different md5sum\n",$NF}' file2 file1
file4.php has a different md5sum
其中file2
和file1
如下
$ cat file1
df7a0edcb7994581430379db56d8d53b /home/user/vanila/file-1.php
e1af39e94239a944440ab2925393ae60 /home/user/vanila/file-2.php
ce74e43d24d9c36cd579e932ee94b152 /home/user/vanila/file-3.php
95b7d47ed7134912270f8d3059100e8c /home/user/vanila/file-4.php
$ cat file2
df7a0edcb7994581430379db56d8d53b /home/user/file-1.php
94b2a24a1fc9883246fc103f22818930 /home/user/file-1.1.php
e1af39e94239a944440ab2925393ae60 /home/user/file-2.php
ce74e43d24d9c36cd579e932ee94b152 /home/user/file-3.php
f5233ee990c50aade7c4e3ab9b4fe524 /home/user/file-4.php
要查找该文件不存在于另一个文件中,
To find the file is not present in one and not in other,
awk -F"/" 'FNR==NR{filelist[$NF]=$NF; next;}!($NF in filelist){printf "%s is an extra file",$NF}' file1 file2
file-1.1.php is an extra file