简体   繁体   中英

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.

This is available in newer versions and with the GNU awk. I'll need this to work with the different versions of 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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