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

Closure

The closure, or asterisk or star, means that the item immediately preceded by * is matched zero or more times. For example, in the given expression, we match a letter, immediately followed by a lowercase letter or digit. The first character class matches a letter. The second character class matches a letter or digit. The star repeats the second character class:

$ echo -e "ca\nc\nc1\n1\n;\nc;\ncc" | awk '/[a-z][a-z0-9]*/'

The output on execution of this code is as follows:

cacc1c;cc

Let's have another example to explain it. In this example, we print all the lines that contain the ca string and it is followed by zero or more occurrences of t:

$ echo -e "ca\ncat\ncatt\nc\ncatterpillar" | awk '/cat*/'

The output on execution of this code ...

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