The primary duty of an exception handler is to get the error out of the lap of the programmer and into the surprised face of the user. Provided you keep this cardinal rule in mind, you can't go far wrong.
Something I often need to do is match lines against a regexp, and print out a matching group within that line. But I have never been able to find a way to do this in awk, and end up resorting to Perl.
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
Something I often need to do is match lines against a regexp, and print out a matching group within that line. But I have never been able to find a way to do this in awk, and end up resorting to Perl.
So - is there a way to do something like this?
/abc([0-9]+)def/ { print group(1); }
so that input of:
abc654def
produces:
654
Thanks!
Comment Responses
you can install gawk,and do like this:
Syntax:
gawk 'mathc($0,regex,array){print array[1]}' file
example:
gawk 'match($0, "https?:\/\/(.*?google.*?)/", array) {print array[1]}' filename
Reply To This Comment