|
awk '# lower - change upper case to lower case
# initialize strings
BEGIN { upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower = "abcdefghijklmnopqrstuvwxyz"
}
# for each input line
{
# see if there is a match for all caps
while (match($0, /[ABCDEFGHIJKLMNOPQRSTUVWXYZ]+/))
#while (match($0, /[A-Z]+/))
# get each cap letter
for (x = RSTART; x < RSTART+RLENGTH; ++x) {
CAP = substr($0, x, 1)
CHAR = index(upper, CAP)
# substitute lowercase for upper
gsub(CAP, substr(lower, CHAR, 1))
}
# print record
print $0
}' $*
上面这段awk脚本,目的是将文件中的大写字母转换为小写字母。我用了才发现在awk中/[A-Z]/匹配的不仅是大写而且还有小写(如果使用第二个while将得不到正确的结果)。
请问谁能够帮我解决awk中/[A-Z]/的匹配问题。 |
|