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

A single number in brackets

A single number in brackets, {n}, matches exactly n occurrence of the preceding expression. For example, the following regular expression matches the line consisting of exactly 5 digits between a and b:

$ awk '/a[0-9]{5}b/'  interval_regex.txt

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

a12345b

If from the emp.dat file, you want to print all the lines in which an employee's phone number had the 9 repeated twice, we can write the regular expression as follows:

$ awk '/[9]{2}/' emp.dat

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

Amit    Sharma  9911887766  amit@yahoo.com      M   lgs     2350John    Kapur   9911556789  john@gmail.com      M   hr      2200Billy   Chabra  9911664321  bily@yahoo.com      M   lgs     1900

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