使用unix终端解析XML [英] Parsing XML using unix terminal
本文介绍了使用unix终端解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有时我需要从XML文件中快速提取一些任意数据,以便将其变为CSV格式。你在Unix终端中最好的做法是什么?我会喜欢一些代码示例,因此我可以如何解决以下问题?
Sometimes I need to quickly extract some arbitrary data from XML files to put into a CSV format. What's your best practices for doing this in the Unix terminal? I would love some code examples, so for instance how can I get the following problem solved?
示例XML输入:
<root>
<myel name="Foo" />
<myel name="Bar" />
</root>
我想要的CSV输出:
Foo,
Bar,
推荐答案
如果你只想要任何元素的名称属性,这里是一个快速但不完整的解决方案。
If you just want the name attributes of any element, here is a quick but incomplete solution.
(你的示例文本在文件 )
(Your example text is in the file example)
grepnameexample | cut -d\-f2,2
| xargs -I {} echo{},
grep "name" example | cut -d"\"" -f2,2 | xargs -I{} echo "{},"
这篇关于使用unix终端解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文