How to (e) grep XML for certain tag content?
问题 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? 回答1: Use awk: awk '/<B>/,/<\/B>/' 回答2: When working with xml files, the best way is to