PepperoniPizza
PepperoniPizza

Reputation: 9102

bash search line matching hash and output it to a file

I have this very large text file 3GB and I need to process only those lines having a MD5 hash. I expect the file to be much shorter after taking out only those lines having an MD5. What I was thinking was doing something like this:

$cat myfile.txt | grep '[a-fA-F0-9]{32}' > only_lines_with_hashes.txt

Thanks

Upvotes: 0

Views: 976

Answers (2)

jkshah
jkshah

Reputation: 11703

Try escaping {} with \. and use of cat is redundant.

grep '[a-fA-F0-9]\{32\}' myfile.txt > only_lines_with_hashes.txt    

Upvotes: 1

Kevin
Kevin

Reputation: 56059

grep uses BREs by default. Those generally don't include {n}, but I believe Gnu grep will accept an escaped version, try

grep '[[:xdigit:]]\{32\}' myfile.txt > hashes.txt

Or tell it the RE is extended, with -E

grep -E '[[:xdigit:]]{32}' myfile.txt > hashes.txt

Upvotes: 3

Related Questions