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

Two numbers in brackets

If there are two numbers, n and m, in brackets, then it means that the preceded item must be matched at least n times but not more than m times. The values of n and m must be non-negative and smaller than 255. For example, to match the occurrence of a minimum of 2 numbers and a maximum of 6 numbers between a and b in a line, we can use the following regular expression:

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

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

a12ba123ba1234ba12345ba111ba111111b

In interval expression, the preceding regular expression should be a single-character regular expression, or if it is a string, it must be enclosed in a bracketed regular expression. For example:

$ awk '/(ab){2,3}/' ...

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