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

Character classes

Character classes, also known as a character set, is a regular expression consisting of a group of characters enclosed in brackets. It matches any one of the enclosed characters, irrespective of the order of occurrence of that character in the bracket. For example, [abcdefgh] matches any of the a, b, c, d, e, f, g, or h characters. 

In the following example, we print the employee information for those whose names begin with any of the characters enclosed within brackets:

$ awk '/^[ ABCDEFGHIJ ]/{ print }' emp.dat

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

Jack    Singh   9857532312  jack@gmail.com      M   hr      2000Jane    Kaur    9837432312  jane@gmail.com      F   hr      1800Eva     Chabra  8827232115  eva@gmail.com       F   lgs     2100Amit Sharma 9911887766 ...

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