GNU awk: accessing captured groups in replacement text

With GNU awk:

echo abbc | awk '{ print gensub(/a(b*)c/, "Here are bees: \\1", "g", $1);}'

See manual here to see the difference between gsub and gensub

gensub() provides an additional feature that is not available in sub()
or gsub(): the ability to specify components of a regexp in the
replacement text. This is done by using parentheses in the regexp to
mark the components and then specifying ā€˜\N’ in the replacement text,
where N is a digit from 1 to 9.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)