tags:

views:

156

answers:

1

Hey Guys,

I need to grab just the md5 value from a file and make it a variable which I can use to compare to another md5 value. The problem is this file looks like this:

a7393f772e34ca16a5854e80d9ec6704 md5

How do I open the file and only grab the actual number in DOS? (Not the "md5" And set it as a variable?

Thanks!

+1  A: 

There's no way to do that with a batch file on MSDOS. However, an NT/W2K/XP/etc. batch file can do it this way:

for /F "tokens=1" %%A in (md5list.txt) do set result=%%A
echo result is %result%
wallyk
Thanks Wallyk. I am running this as a .bat file, doesn't that use MS-DOS? I will be running this in a Win2003 env. I put your command in a .bat file and ran it and this was the output:C:\ipod>test.batC:\ipod>for /F "tokens=1" %A in (file.txt) do set result=%AC:\ipod>set result={\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0C:\ipod>set result={\*\generatorC:\ipod>set result=}C:\ipod>echo result is }result is }
Steve
No, it won't use MSDOS unless you invoke command.com, and even then it's not really MSDOS.It looks like file.txt isn't formatted as expected.
wallyk
@Steve: It appears as though your file.txt file is in fact an .rtf format file. Save it as plain text and try again.
Greg Hewgill
That was it guys! Thanks so much for the help!
Steve
I have one problem, my file never uses the same name so I cannot use a text file like list.txt. We automatically download two files a .dat file and a .md5 file. Both of them have a unique filename which changes everytime (V2,V3,etc). Essentially I run the .dat file through an md5 app and it produces the correct md5 which I want to compare to the .md5 file (after I grep out just the number) But when I tried to run the script with the solution you provided I just changed the (list.txt) to (*.md5) but it failed. Any other way to grep out the number using an *.md5 file in your solution?
Steve
I just tested and if I specify the entire .md5 filename it works fine but is it possible to use a wildcard with this command? This will be the only md5 file in the directory.
Steve
If you know you've only got one .md5 file in the subdirectory, why not just rename it first : REN *.md5 list.txtThis will work fine providing there's just one .md5 there.
Sam