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

Positive closure

The positive closure or plus (+) means that the item immediately preceded by + is matched one or more times. For example, the ca+t would match cat and caat, whereas ca*t would match all three, as follows:

$ echo -e "cat\nct\ncaat\ncbt" | awk '/ca+t/'

The output on execution of the preceding code is as follows:

catcaat

A summary of positive closure (+) is as follows:

Pattern

Matches

A+

Matches the single AAA, or AAA, and so on

AB+C

Matches ABCABBC, or ABBBC, and so on

[0-9]+

Matches one or more numbers

[0-9][0-9]+

Matches two or more numbers

^A+

Matches any line beginning with one or more A letters

^A\+

Matches any line starting with A+

^AA+

Matches any line starting with ...

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