O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Backreferencing in regular expressions – sed and grep

If we group the regular expressions with more than one character and place it inside parentheses, it becomes a sub-expression. This sub-expression is matched and the output of the match is remembered and can be recalled if you find the same pattern occurrence again during the subsequent match operation.

We can recall the remembered pattern with \ followed by a single digit. We can have a maximum of nine different remembered patterns. Each occurrence of ( starts a new pattern of a sub-expression. This process of recalling remembered patterns is called the backreferencing of sub-expressions.

Sub-expressions are represented by enclosing a regex between parentheses: → \(regex\)  

A backreference ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required