我有大量带标签的字符串:
watch <TEAM>Philly's</TEAM> Game
what's on <TIME>Wednesday night eight o'clock</TIME>
我想将除 XML 标记之外的所有文本小写。即
watch <TEAM>philly's</TEAM> game
what's on <TIME>wednesday night eight o'clock</TIME>
我可以使用 awk 将所有文本小写:
awk '{print tolower($0)}' file.txt
但不知道如何避免 XML 标记。欢迎使用任何语言/工具。
最佳答案
这个 sed (gnu) 单行代码可能会有所帮助:
sed -r 's/([^<>]*)($|<)/\L\1\E\2/g'
以你的例子:
kent$ echo "watch <TEAM>Philly's</TEAM> Game
what's on <TIME>Wednesday night eight o'clock</TIME>"|sed -r 's/([^<>]*)($|<)/\L\1\E\2/g'
watch <TEAM>philly's</TEAM> game
what's on <TIME>wednesday night eight o'clock</TIME>
关于xml - 除 xml 标签外的所有文本小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27326431/