Bash - 编辑代码行

时间:2017-01-12 16:46:16

标签: linux bash shell awk md5

此问题与Bash - Compare 2 lists of files with their md5 check sums

有关

我的问题是如何编辑以下代码以显示文件的整个路径,而不仅仅是它的名称:

awk -F"/" 'FNR==NR{filearray[$1]=$NF; next }!($1 in filearray){printf "%s has a different md5sum\n",$NF}' file1 file2

awk -F"/" 'FNR==NR{filelist[$NF]=$NF; next;}!($NF in filelist){printf "%s is an extra file",$NF}' file1 file2

有关详细信息,请查看其他问题!

感谢大家的时间和帮助!

1 个答案:

答案 0 :(得分:3)

使用GNU Awk字符串操作split-function来拆分匹配的行,在本例中为$0并将其作为单独的元素存储在array中。

 awk -F"/" 'FNR==NR{filearray[$1]=$NF; next }!($1 in filearray){split($0,array," ");printf "%s has a different md5sum or do not exist in the vanilla core files\n",array[2]}' file2 file1
/home/user/vanila/file-4.php has a different md5sum or do not exist in the vanilla core files

和文件

 awk -F"/" 'FNR==NR{filelist[$NF]=$NF; next;}!($NF in filelist){split($0,array," "); printf "%s is an extra file\n",array[2]}' file1 file2
/home/user/file-1.1.php is an extra file