I have a file where I want to grep for an md5 hash. I was able to do that but how can I display the match to stdout?
When I do grep -e "[0-9a-f]\{32\}" file
I just get:
Binary file file matches.
Is there a way to print the result to stdout?
From https://www.gnu.org/software/grep/manual/html_node/Usage.html
Why does grep report “Binary file matches”?
If grep listed all matching “lines” from a binary file, it would probably generate output > that is not useful, and it might even muck up your display. So GNU grep suppresses output > from files that appear to be binary files. To force GNU grep to output lines even from files that appear to be binary, use the -a or ‘--binary-files=text’ option. To eliminate > the “Binary file matches” messages, use the -I or ‘--binary-files=without-match’ option.
grep -e "[0-9a-f]\{32\}" file --binary-files=text
grep -o to output only the match, instead of the whole line: grep -e -o --binary-files=text"[0-9a-f]\{32\}" file
file? if it's not really a binary file, trygrep -a .... If it is binary, trygrep -a -o ...or something likestrings file | grep ...fileto be a text file?grep. Butsed -nE 's/.*([0-9a-f]{32}).*/\1/p' fileshould do the job