上QQ阅读APP看书,第一时间看更新
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 2350
John Kapur 9911556789 john@gmail.com M hr 2200
Billy Chabra 9911664321 bily@yahoo.com M lgs 1900