如何使用 split 函数将驼峰式字符串拆分为 awk 中的数组?
Input:
STRING="camelCasedExample"
期望的结果:
WORDS[1]="camel"
WORDS[2]="Cased"
WORDS[3]="Example"
糟糕的尝试:
split(STRING, WORDS, /([a-z])([A-Z])/);
不好的结果:
WORDS[1]="came"
WORDS[2]="ase"
WORDS[3]="xample"
你不能这样做split()
单独这就是为什么 GNU awk 有patsplit()
:
$ awk 'BEGIN {
patsplit("camelCasedExample",words,/(^|[[:upper:]])[[:lower:]]+/)
for ( i in words ) print words[i]
}'
camel
Cased
Example
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)