本文介绍了如何从 Unix 命令行中删除 XML 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 grepping 一个 XML 文件,它给我这样的输出:
I am grepping an XML File, which gives me output like this:
<tag>data</tag>
<tag>more data</tag>
...
注意,这是一个平面文件,而不是 XML 树.我想删除 XML 标记,只显示其间的数据.我正在从命令行执行所有这些操作,并且想知道是否有比将其通过管道输入 awk 两次更好的方法...
Note, this is a flat file, not an XML tree. I want to remove the XML tags and just display the data in between. I'm doing all this from the command line and was wondering if there is a better way than piping it into awk twice...
cat file.xml | awk -F'>' '{print $2}' | awk -F'<' '{print $1}'
理想情况下,我想在一个命令中完成此操作
Ideally, I would like to do this in one command
推荐答案
如果你的文件看起来像这样,那么 sed
可以帮助你:
If your file looks just like that, then sed
can help you:
sed -e 's/<[^>]*>//g' file.xml
这篇关于如何从 Unix 命令行中删除 XML 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!