Regex awk版本3.1.7中的字符类范围

Regex awk版本3.1.7中的字符类范围,regex,awk,posix,character-class,Regex,Awk,Posix,Character Class,与grep不同,我无法在'awk'中定义数字字符类的大小/范围。任何正确方向的线索都是值得赞赏的 cat input 1abc 12abc 123abc 1234abc 12345abc 在grep中,我可以定义数字字符类的大小/长度 grep -P '^\d{3,4}' input #or grep -P '^[[:digit:]]{3,4}' input 123abc 1234abc 12345abc grep -P '^\d{4,}' input #or grep -P '^[[:di

grep
不同,我无法在'awk'中定义数字字符类的大小/范围。任何正确方向的线索都是值得赞赏的

cat input
1abc
12abc
123abc
1234abc
12345abc
grep
中,我可以定义数字字符类的大小/长度

grep -P '^\d{3,4}' input #or grep -P '^[[:digit:]]{3,4}' input
123abc
1234abc
12345abc
grep -P '^\d{4,}' input  #or grep -P '^[[:digit:]]{4,}' input 
1234abc
12345abc
现在我想用awk来做这个,但是同一个正则表达式不起作用

例如,下面的命令不提供任何输出

awk '/^[[:digit:]]{3,4}/' input 
awk '/^([[:digit:]]){3,4}/' input
我希望上面的命令能够打印出来

123abc
1234abc
12345abc
注1:目前我用它来定义范围,但对于大范围来说并不合适

awk '/^[0-9][0-9]?[0-9]?/' input
注2:

awk --version |head -1
GNU Awk 3.1.7
使用
--posix
选项

在awk版本3的手册页中,您可以阅读:

r{n,m}     One or two numbers inside braces denote an interval expression.  If there is one number in the braces, the preceding regu-
           lar  expression  r  is  repeated  n times.  If there are two numbers separated by a comma, r is repeated n to m times.  If
           there is one number followed by a comma, then r is repeated at least n times.
           Interval expressions are only available if either --posix or --re-interval is specified on the command line.

不能复制。GNU Awk 4.1.4可以精确地生成您想要的输出。在RHEL 5和GNU Awk 3.1.5中,您必须使用
--posix
选项。@Jdamian,谢谢,过去几个小时我一直在挠头。这是AWK版本3及更早版本的手册页。在版本4中,默认情况下支持间隔表达式。