Could anyone show me how I can find all strings in a file which are alphanumeric and may contain either the symbol _ or # and end in the hex code 0x00. I've tried using grep with the following options but it doesn't seem to work: -z [a-zA-Z0-9_]*
Thanks in advance.
Here's an example of some of the strings im trying to extract, as you can see they end with the hex code 0x00, vary in length and although this specific example doesn't show they can contain 0-9, an underscore (_) or a hash (#).
[a-zA-Z0-9_]+matches 1 or more of the characters as you'd expect, but the
*) will require the
-Eoption to grep. And always put your regex in quotes - ghoti 2012-04-03 23:38
\wis a synonym for
[0-9A-Za-z]. And why are you escaping the #? And how are you handling the null? Note that the
--null-dataoption to GNU grep doesn't exist in version 2.5.1, which is what's used in FreeBSD and Mac OS X. Also doesn't exist in non-GNU grep. The OP didn't specify Linux - ghoti 2012-04-03 23:48
When I run this all I get is 'Binary file /cygdrive/d/dump.bin matches'? Im using grep in cygwin. – Twisted89 Apr 4 at 10:09
MrJames answer does not include the
-a. Plus his putting
\w in brackets simply doesnt work.
grep -Eaoz "(\w|_|#)*" FILE