xml - 除 xml 标签外的所有文本小写

标签 xml linux awk sed

我有大量带标签的字符串:

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/

相关文章:

xml - xml中的 'base'属性是什么?

java - 解码异常 : unexpected element on XML just been Marshaller

c - 无法通过 IDA 在 gdbserver 中设置断点

regex - 如何使用sed删除echo输出的一些行

linux - 在 awk 命令 shell 中使用日期

xml - 在 ActionScript 3 中是否需要/推荐在 XML 中测试节点是否存在?

PHP:如何从 android .apk 文件中获取版本?

linux - awk 的多输入文件

python - 如何将现有环境克隆到anaconda中的基础环境

linux - 使用 awk 或 sed 替换 _ 之前的字符串