Using grep to search for hex strings in a file

This seems to work for me: LANG=C grep –only-matching –byte-offset –binary –text –perl-regexp “<\x-hex pattern>” <file> short form: LANG=C grep -obUaP “<\x-hex pattern>” <file> Example: LANG=C grep -obUaP “\x01\x02” /bin/grep Output (cygwin binary): 153: <\x01\x02> 33210: <\x01\x02> 53453: <\x01\x02> So you can grep this again to extract offsets. But don’t forget to use binary mode … Read more

Grep output with multiple Colors?

You can cascade greps with different colors by specifying –color=always and using the regular expression ‘foo|$’ to pass all lines. For example: tail -f myfwlog | GREP_COLOR=’01;36′ egrep –color=always ‘ssh|$’ | GREP_COLOR=’01;31′ egrep -i –color=always ‘drop|deny|$’ If you want the entire line to be highlighted, update your regular expression accordingly: …. GREP_COLOR=’01;31′ egrep -i –color=always … Read more

How can I use grep to find a word inside a folder?

grep -nr ‘yourString*’ . The dot at the end searches the current directory. Meaning for each parameter: -n Show relative line number in the file ‘yourString*’ String for search, followed by a wildcard character -r Recursively search subdirectories listed . Directory for search (current directory) grep -nr ‘MobileAppSer*’ . (Would find MobileAppServlet.java or MobileAppServlet.class or … Read more