简体   繁体   English

awk正则表达式重复次数{n}在mawk 1.2版上不起作用

[英]awk regex number of repetition {n} doesn't work on mawk version 1.2

Is there a workaround to be able to check for patterns of type 是否有一种解决方法可以检查类型的模式

/[pattern]{n}/

where n is the number of repetitions in mawk version 1.2. 其中n是mawk 1.2版中的重复次数。

This is available in newer versions and with the GNU awk. 这在较新的版本中以及GNU awk中都可用。 I'll need this to work with the different versions of awk. 我将需要使用它来处理不同版本的awk。

One of these MAY be what you want: 其中之一可能是您想要的:

$ cat file
abcbcd
abcbcbcd

$ awk '/(bc){3}/' file
abcbcbcd

$ awk 'gsub(/bc/,"&")>=3' file
abcbcbcd

$ awk 'match($0,/bc/) && (n=RLENGTH) && match($0,/(bc)+/) && ((RLENGTH/n)>=3)' file
abcbcbcd

but without sample input and expected output we're just guessing. 但是没有样本输入和预期输出,我们只是在猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM