The usual (and correct) answer for backreferences in awk (for example, the answer you can get on #awk for this question) is: "you can't do backreferences in awk". That is only partly true. If you need to //**match**// a pattern using a regular expression with backreferences, like eg you do in sed {{{ sed sed -n '/\(foo\)\(bar\).*\2\1/p' # prints lines with "foobar" and "barfoo" later in the line }}} or similar things, then well, you can't do that easily with awk. But if you are using backreferences during string substitution, to insert text previously captured by a capture group, then you will almost certainly be able to get what you want with awk. Following are some hints: * First and easiest answer (requires GNU awk): use gensub(). It supports backreferences natively. * Second answer: sometimes you don't really need backreferences, since what you want can be accomplished without. Examples: {{{ sed echo 'foo123bar' | sed 's/.*\([0-9]\{1,\}\).*/\1/' echo 'blah <a href="http://some.site.tld/page1.html">blah blah</a>' | sed 's/.*"\([^"]*\)".*/\1/' }}} Both things can be done in awk (and sed as well!) without the need of backreferences. You just delete the part of the line you don't need: {{{ awk awk '{gsub(/^[a-z]*|[a-z]*$/,"");print}' # 1st example awk '{gsub(/^[^"]*"|"[^"]*$/,"");print}' # 2nd example }}} Generally speaking, however, the above methods (both sed and awk) require that you have only one matching substring to extract per line. * Third answer: see [[GeneralizedTextReplacement]] for a detailed discussion of a framework for generalized text replacement, including an explanation on how to emulate backreferences with awk.
Summary:
This change is a minor edit.
Username: