Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

How to MD5 the contents of a TXT file line by line


pawnflow's Avatar
Member
0 0

So I kind of need to MD5 Hash an entire txt files' contents line by line.

Here's part of my list as an example:

apple orange grape pineapple banana

I need to basically find the md5 hash of every single one of the words and display it like so,

apple:(md5 hash of apple) orange:(md5 hash of orange) grape:(md5 hash of grape) ect…

I could do it manually but the txt file is 25,000,000 lines long but it would take forever.

Anyone know how I could do that?


gobzi's Avatar
Member
10 0

In Linux: for i in cat testmd5; do echo -n $i | md5sum | awk '{print $1}' >> md5_out; done; paste -d " " testmd5 md5_out | tr ' ' ':' > final

Either change your file name to testmd5 or the other way around. md5_out should contain the hashes and final contains the final output thumbs up

If you want to repeat that just rm md5_out first


Kulverstukas's Avatar
Member
0 0

There are a lot of ways in doing this. Your question needs more detail, like what platform, what language, etc…


gobzi's Avatar
Member
10 0

A colleague of mine wrote that, which is better than mine :D

for i in cat testmd5; do echo $i:$(echo -n $i | md5sum | cut -d'-' -f1) ; done > final


pawnflow's Avatar
Member
0 0

Kulverstukas wrote: There are a lot of ways in doing this. Your question needs more detail, like what platform, what language, etc…

My bad. I was thinking of doing this in the bash command line or in C++.


pawnflow's Avatar
Member
0 0

gobzi wrote: A colleague of mine wrote that, which is better than mine :D

for i in cat testmd5; do echo $i:$(echo -n $i | md5sum | cut -d'-' -f1) ; done > final

Thank you gobzi, that worked.