I have two files MD1
and MD2
.
MD1
contains md5sums:
5f31caf675f2542a971582442a6625f6 /root/md5filescreator/hash1.txt
4efe4ba4ba9fd45a29a57893906dcd30 /root/md5filescreator/hash2.txt
1364cdba38ec62d7b711319ff60dea01 /root/md5filescreator/hash3.txt
where hash1
, hash2
and hash3
are three files present in folder md5filescreator
.
Similarly MD2
contains:
163559001ec29c4bbbbe96344373760a /root/md5filescreators/hash1.txt
4efe4ba4ba9fd45a29a57893906dcd30 /root/md5filescreators/hash2.txt
1364cdba38ec62d7b711319ff60dea01 /root/md5filescreators/hash3.txt
where these files are in folder md5filescreators
.
I want to compare the checksums in md5filescreator
with the corresponding file's checksum in md5filecreators
.
The shell script should return OK for files with same checksums and FALSE for those which are not, along with the file names.
Can this be done using md5sum --check
(since it normally checks for any changes in only 1 MD5 file)?
Best Answer
No, it can't.
md5sum --check
is meant to read the path to each file in the second column of the input files and check their MD5 checksum agains the checksum reported on the first column; if you want to directly compare the checksums in the two files, you'll have to compare the text files.Using
paste
+ AWK you could do:paste file1 file2
: joins line N offile1
on line N offile2
;awk '{x = $1 == $3 ? "OK" : "FALSE"; print $2" "x}'
: if the first field is equal to the third field (i.e. the MD5 sums match), assigns "OK" tox
, otherwise assigns "FALSE" tox
and prints the second field (i.e. the filename) followed by the value ofx
.