I need help extracting an XML string from file like this:
<line> <Start_Time>2016-May-18 17.06.17.504</Start_Time> <Domain>pciereg062</Domain> <Injected_tags> before xml started ; AUTOMATIC-REPRODUCTION-stopped on barrier ; </Injected_tags> </line> <line> <Start_Time>2016-May-18 17.08.53.585</Start_Time> <Domain>adv191</Domain> <Injected_tags>port-num-0 ; port-num-0 actual-FW-14.16.0234 ; </Injected_tags> </line> I want to extract the domain name which is in injected_tags (which will come always after domain) string stopped on barrier.
Is there a simple bash utility to do this (grep, awk, sed)?
From the example above, the output should be pciereg062 and not adv191.
grep -B 2 'stopped on barrier' input.xml | grep -Po '(?<=<Domain>).*(?=</Domain>)'. You really should look into some XML parser like Cyrus suggested.