I have a xml file as follows
<Module dataPath="/abc/def/xyz" handler="DataRegistry" id="id1" path="test.so"/>
<Module id="id2" path="/my/file/path">
<Config>
<Source cutoffpackage="1" dailyStart="20060819" dataPath="/abc/def/xyz" />
<Source cutoffpackage="1" dailyStart="20060819" dataPath="/abc/def/xyz" id="V2"/>
</Config>
</Module>
I just want to extract value of dataPath
from every moduleid
.
I was using, the command like
`grep 'id2' file | grep -ioPm1 "(?<=DataPath=)[^ ]+"`
which is giving me from the first module id, not for second module id. because second module is in multiple lines.
How can i do this using shell script?
Desired output would be– if i want to get the datapath of id1 module, then is should get
/my/file/path
Of for second module id, say id2, i should get datapath separated by comma
/my/file/path, /my/file/path
Or my second approach to grep the datapath is to replace the newline character
between <Module
and </Module>
only, then i can use grep.