tags:

views:

273

answers:

1

If I have an awk command

pattern { ... }

and pattern uses a capturing group, how can I access the string so captured in the block?

A: 

That was a stroll down memory lane...

I replaced awk by perl a long time ago.

Apparently the AWK regular expression engine does not capture its groups.

you might consider using something like :

perl -n -e'/test(\d+)/ && print $1'

the -n flag causes perl to loop over every line like awk does.

Peter Tillemans
Apparently someone disagrees. This web page is from 2005 : http://www.tek-tips.com/faqs.cfm?fid=5674It confirms that you cannot reuse matched groups in awk.
Peter Tillemans
[this article](http://www.catonmat.net/blog/ten-awk-tips-tricks-and-pitfalls/) seems to agree with you too.
rampion
As the tek-tips article states, gawk can re-use capture groups.
Dennis Williamson