watch_1394 发表于 2005-2-17 03:44:14

是awk高手的请进。

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, /+/))
      #while (match($0, /+/))
      # 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中//匹配的不仅是大写而且还有小写(如果使用第二个while将得不到正确的结果)。
请问谁能够帮我解决awk中//的匹配问题。

dannycat 发表于 2005-2-18 13:51:47

有这等事?

使用 LANG=C 来运行 awk。

或者使用[[:upper:]] 来代替。

kornlee 发表于 2005-2-24 00:36:11


awk '{print tolower($0)}'
这样可以么

Netcrawller 发表于 2005-10-11 15:20:20

可以
页: [1]
查看完整版本: 是awk高手的请进。