Displaying only data matching a pattern?
Shawn O'Shea
shawn at eth0.net
Mon Feb 2 13:06:49 EST 2009
On Mon, Feb 2, 2009 at 12:07 PM, kenta <kenta at guster.net> wrote:
>
>
> Actually I need to get the info regardless of delimiters so matching
> any hex digits of a certain length works for me. I'd sent an e-mail
> before but I used the wrong address so maybe it didn't go through, for
> som reason the gnu-port of grep for win32 has no -o option. :(
>
You could try it this way in gawk:
$ cat foo
foofoo:A1234567890B\barbar
foofoo:C9234567890E\barbar
foofoo:A8234567890B\barbar
foofoo:F7234567890D\barbar
$ gawk --posix '{ if (match($0,/[[:xdigit:]]{12}/)) print
substr($0,RSTART,RLENGTH) }' foo
A1234567890B
C9234567890E
A8234567890B
F7234567890D
You need --posix for [:xdigit:] and the curly braces ( {} ) to work. This
basically says:
if the line ($0) matches 12 hexdigits ([:xdigit:]) in a row:
print a substring of the line ($0) starting at RSTART and going for
RLENGTH characters
match() sets RSTART and RLENGTH for you on a match.
-Shawn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20090202/ea28a4d9/attachment.html
More information about the gnhlug-discuss
mailing list