March 2018
Beginner to intermediate
416 pages
9h 24m
English
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
Read now
Unlock full access