Mezz
Mezz

Reputation: 130

How to search through multiple xml files for the occurence of a string in between 2 tags in linux?

I have around 100 xml files in which there is an inconsistency of how to euro sign (€) is displayed as the character or as (&euro).

First to prove that these 2 strings occured in the same files, i used grep :

grep -e "&euro" -e "€" -R /home/xml/ -o

&amp;euro only occurs between the tags <conditions> and <directions>.

e.g.

<directions> text text text : price : 19.99 &amp;euro text text&amp;euro </directions>
<conditions><tag><tag2> text text text &amp;euro text&amp;euro </tag2></tag></conditions>

I would like to search for the occurence of the € sign in any strings in between these tags.

how can I achieve this?

Upvotes: 0

Views: 1073

Answers (1)

Rudi Angela
Rudi Angela

Reputation: 1483

Here's how I'd do it with element 'directions':

find . -name "*.xml" | xargs grep "<directions>.*\&amp;euro.*<\/directions>"

Same can be applied to 'conditions' element.

Upvotes: 1

Related Questions