如何(e)为某些标记内容grep XML? [英] How to (e) grep XML for certain tag content?

查看:125
本文介绍了如何(e)为某些标记内容grep XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能(grep)所有的内容在一个特定的标签块之间?



假设输入文件在下面,我想得到输出B-标签如此:

 < B>< C>测试< / C>< / B> 
< B> Test2< / B>

我尝试了以下grep来搜索所有XML文件,其内容介于 < B> < / B> 标签。

  grep'< B>。*< / B>'.xml 

但它不起作用。



对于以下输入:

 < A> 
< B>
< C>测试< / C>
< / B>
< D>
< / D>
< B>
Test2
< / B>
< / A>

有什么想法?

解决方案

使用awk:

  awk'/< B> /,/< \ / B> ; /'


How can I (e)grep all content between a certain tag block?

Assume input file below, I want to get as output all characters between the B-tags so:

<B><C>Test</C></B>
<B>Test2</B>

I tried the following grep to search all XML files with the content between the <B> and </B> tags.

grep '<B>.*</B>' *.xml

but it did not work.

For the following input:

<A>
 <B>
  <C>Test</C>
 </B>
 <D>
 </D>
 <B>
    Test2
 </B>
</A>

Any ideas?

解决方案

Use awk:

awk '/<B>/,/<\/B>/'

这篇关于如何(e)为某些标记内容grep XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆