How do I perform action on all matching groups when the pattern matches multiple times in a line?
To illustrate, I want to search for /Hello! (\\d+)/
an
There is no gawk function to match the same pattern multiple times in a line. Unless you know exactly how many times the pattern repeats.
Having this, you have to iterate "manually" on all matches in the same line. For your example input, it would be:
{
from = 0
pos = match( $0, /Hello! ([0-9]+)/, val )
while( 0 < pos )
{
print val[1]
from += pos + val[0, "length"]
pos = match( substr( $0, from ), /Hello! ([0-9]+)/, val )
}
}
If the pattern shall match over a linefeed, you have to modify the input record separator - RS