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

Complemented named character classes

In complemented named character classes, the first character after [ is caret, ^, and it is followed by the named character class, which is enclosed in '[:' and ':]'. For example, if you want to search for a line without letters (lowercase), we can write it as follows:

$ echo -e "a\nb\nc\n1\n2\nd\n3" | awk '/[^[:lower:]]/'

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

123

We can mix the old and new POSIX styles, for example, to any number between 1-5 or any lowercase letter. For this, we can use the following:

$ echo -e "a\n1\ne\n5\nz\n8" | awk '/[1-5[:lower:]]/'

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

a1e5z

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