how to set sed to show random md5 hash!
Hello, does anyone know how to make sed get the md5 checksum hash from a file.
I have some files that have random md5 checksum hash on it content, trying to figure out how i can set sed to know the md5 hash between all the lines and words in the files. md5 is a 32 character string of a random hexadecimal numbers [0-9][a-f]. i tried to set identifier in sed to show the hash after it, but it also show the worlds in the same line after the hash. any idea ? |
You will have to show what you have so far, or a sample line before someone can provide much help.
You probably want to use the form: sed '/<md5pattern>/s/.*\(<md5pattern>\).*/\1/' file to select the line with the md5sum and to only output the match. |
no jschiwal, i dont have some thing to match.
some of the files they have "md5sum=" before the hash, so i can get the hash, but it show also words after the hash for example: file: Quote:
Quote:
Quote:
thanks |
Why not gawk?
Code:
gawk '/md5sum=/{print substr($0,index($0,"md5sum=")+7,32)}' file Code:
gawk '/md5sum=/{print substr($0,index($0,"md5sum="),39)}' file |
thanks colucix, awk work fine, is there a way to get the hash without any identifier, i mean if the "md5sum=" is a variable and the hash also a variable. not all of the files have "md5sum=".
thanks again |
So you want to match any sequence of 32 characters matching digits or letter from a to f (hexadecimal digits), right? Something like this should work
Code:
gawk --posix '{idx = match($0,/[0-9a-f]{32}/); if ( RLENGTH == 32 ) print substr($0,idx,RLENGTH)}' file |
Thanks colucix, it didn't work. but i got the idea. thanks a gain.
Quote:
|
Strange... it works on my system. Which version of awk do you have?
|
h4x0r# awk --version
awk version 20070501 (FreeBSD) |
Hmmm... once I read about the FreeBSD version of awk not supporting extended regular expressions and in particular the interval expression I used in the command above. I don't know much about FreeBSD, but as alternative you can try something like
Code:
grep -E -o '[0-9a-f]{32}' file |
grep work fine thanks dude, is there a difference between awk and gawk?
|
Yes. A lot of differences, in the sense that the GNU awk (gawk) has introduced new advanced features not available in standard unix's awk. Portability of your awk code is an issue when you are used to the GNU extension of awk.
|
aha, thanks for the info brother.
|
i install gawk on my FreeBSD, the posix work fine with it.
Quote:
|
Good to know! You're welcome! :)
|
All times are GMT -5. The time now is 05:44 PM. |