I'm referencing to
answer to: GNU awk: accessing captured groups in replacement text
but whith ?
Quantifier for regex matching
I would like to make if
statement or ternary operator ?:
or something more elegant so that if regex group that is backreferenced with \\1
returns nonempty string then, one arbitrary string (\\1
is not excluded) is inserted and if it returns empty string some other arbitrary string is inserted. My example works when capturing group returns nonempty string, but doesn't return expected branch "B" when backreference is empty. How to make conditional branching based on backreferenced values?
echo abba | awk '{ print gensub(/a(b*)?a/, "\\1"?"A":"B", "g", $0)}'