It's just a way of identifying capture groups and saving the matching strings as
array elements. Just like sed has 's/\(x\)\(y\)/\1-\2/' gawk in addition to
gensub() for THAT simple task has 'match($0,/(x)(y)/,a) { print a[1]"-"a[2] }'
which is much more powerful because you can do other operations on the captured
strings, e.g. 'match($0,/(x)(y)/,a) { print a[1]*7"-"int(a[2]) }'.
btw I just noticed I had a bug in my script, I wasn't unwinding the sub()s in
the right order so by converting "aA" back to "a" first I was creating the
possibility of "aB" being in the field as something other than the {-replacement
I originally created it to be. Basically you need to unwind the sub()s on each
field in the reverse order you did them on the record for the script to be robust.
This is how it should be done:
$ awk '{
gsub(/a/,"aA")
gsub(/{/,"aB")
gsub(/}/,"aC")
gsub(/aBaB/,"{")
gsub(/aCaC/,"}")
while ( match($0,/(.*)({[^{}]*})(.*)/,a) ) {
gsub(/[{}]/,"&&",a[2])
gsub(/aC/,"}",a[2])
gsub(/aB/,"{",a[2])
gsub(/aA/,"a",a[2])
print a[2]
$0 = a[1] a[3]
}
}' file
Regards,
Ed.