|
Answer» Hello,
I'm needing some help constructing a batch file which compares some preexisting hashes.
The hashes are in a text file, ONE per line, with the hash first, followed by a single space, followed by the filename. e.g. 7CD182468A6D54348C212231F27E997D file.ext The filenames are enumerated, starting at 0. e.g. 0.ext 554.ext 3251235.ext Inside the text file there are 3 hashes with the same number. Their filenames are prefixed with an A, B, or C. e.g. A3251235.ext B3251235.ext C3251235.ext
Is it possible to use a batch file to compare each set of 3 hashes?
I have one other option in how these hashes can be stored. Instead of having the same number 3 times in a single file(prefixed as in the example above)--I have the means to have 3 separate text files. If I use this METHOD, the prefixes would not need to be used.
Any insight into how to get started with this would be appreciated. Thank you.Do you mean that you have a bunch of hashes + filename in a text file, and mixed in with them at any three line numbers are three filenames which are the same, except for a leading A/B/C in the filename.
You want to extract these three and compare the hash value to see if they are the same? Is that it?
Or are there only three hashes in the text file?That's it.
Well, every hash+filename is part of a group of 3. I need all of them to be compared within their group.Does each set of three appear one after the other, then another set of three, and another set of three, etc?They are in alphabetic > numerical order. So, A0 through A???, then B0 through B???, etc.You mean they are ordered by hash?
Does each group of three follow the next one, or are the filenames ordered by the hash value?
So if one file has a different hash it COULD be anywhere in the file and not adjacent to the other two with the same hash value?Sorry for any confusion. The individual lines of the text file are ordered by the filename, not the hash. The filenames prefixed with an 'A' will be first, followed by 'B', and finished with 'C'.
If there were 9 hashes it would look like this:
7CD182468A6D54348C212231F27E997D A0.ext 0DDA55ED49858ADB143B8A86DA49AE17 A1.ext 3079A8613600B43A53B8B5E3907692DE A2.ext 7CD182468A6D54348C212231F27E997D B0.ext 0DDA55ED49858ADB143B8A86DA49AE17 B1.ext 3079A8613600B43A53B8B5E3907692DE B2.ext 7CD182468A6D54348C212231F27E997D C0.ext 0DDA55ED49858ADB143B8A86DA49AE17 C1.ext 3079A8613600B43A53B8B5E3907692DE C2.ext
I also have the ability to have these be in 3 separate text files, instead of together in 1 file with prefixes.This works in my tests. INPUT file is file.txt. Error file is "result.compare.txt" if MISMATCHES are found.
It will report the filename alone, if any mismatch is found between the three versions of the filename.
Code: [Select]@echo off set "file=file.txt" del "result.compare.txt" 2>nul setlocal enabledelayedexpansion for /f "tokens=1,*" %%a in ('type "%file%"') do ( set "a=%%a" set "char=%%b" set "name=!char:~1!" set "char=!char:~0,1!" if /i "!char!"=="A" ( for /f "tokens=1,*" %%c in ('findstr /i /c:" B!name!" "%file%"') do set "b=%%c" for /f "tokens=1,*" %%e in ('findstr /i /c:" C!name!" "%file%"') do set "c=%%e" if "!a!!b!!c!"=="!c!!a!!b!" ( echo "!name!" passed ) else ( echo "!name!" failed compare >> "result.compare.txt" echo "!name!" failed compare ) ) ) pause
|