This question already has an answer here:

I have file filestore.xml from which I need to extract /local/armdata/data/filestore1, /local/armdata/data/filestore2.

grep binariesDir filestore.xml

Is there any way to do this?

marked as duplicate by schily, thrig, Romeo Ninov, Ouki, Archemar Oct 24 '18 at 5:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • grep binariesDir filestore.xml <binariesDir>/local/armdata/data/filestore1</binariesDir> <binariesDir>/local/armdata/data/filestore2</binariesDir> – rajesh Oct 23 '18 at 6:20
  • Please don't add information in the comments, edit the question, especially if it needs formatting. – RalfFriedl Oct 23 '18 at 6:37

Using XMLStarlet:

xml sel -t -v '//binariesDir' filestore.xml

on Ubuntu with xmlstarlet package installed, I need to use this:

xmlstarlet sel -t -v '//binariesDir' filestore.xml

You can use sed.

sed -nre 's:^.*<binariesDir>(.*)</binariesDir>.*$:\1:p' filestore.xml

This handles both the searching for binariesDir and extracting the value between <binariesDir> and </binariesDir>.

Not the answer you're looking for? Browse other questions tagged or ask your own question.