I have a simple xml file,need the output with the <value> tag and <result> tag
text.xml
<test-method status="FAIL" duration="45">
<value>
Id=C18
</value>
<result>
wrong paramter
</result>
</test-method>
<test-method status="FAIL" duration="45">
<value>
Id=C19
</value>
<result>
Data Issue
</result>
</test-method>
<test-method status="FAIL" duration="5">
<value>
Id=C20
</value>
<result>
mismtach
</result>
</test-method>
Output:
id=C18 wrong parameter
id=C19 data issue
id=C20 mismatch
Thanks
sed -n '/<value>\|<result>/ {n;p}' file
--- Post updated at 23:34 ---
awk '/<value>/ {getline tmp}; /<result>/ {getline; print tmp,$0}' file
--- Post updated at 23:38 ---
sed -n '/<value>/ {n;h}; /<result>/ {n;H;x;s/\n/ /;p}' file
--- Post updated at 23:43 ---
sed -n '/<value>/ {n;h}; /<result>/! b; n;H;x;s/\n/ /p' file
2 Likes
Thanks nezabudka . my <results> has multiple lines, only the first line gets displayed when using the command sed -n '/<value>/ {n;h}; /<result>/ {n;H;x;s/\n/ /;p}' file
sed -n '/<value>/ {n;h}; /<result>/ {:1;n;/<\/result>/! {H;b1};x;s/\n/ /g;p}'
--- Post updated at 09:07 ---
sed -n '/<value>/ {n;h}; /<result>/! b; :1;n;/<\/result>/! {H;b1};x;s/\n/ /g;p'
1 Like
awk '{gsub(/(\s<.*>)?\s/, " ")} !(NR%2)' RS='<value>|<\\/result>' file
jgt
May 15, 2019, 5:32pm
6
Create xm1
while read a
do
read b
echo $a $b
done
grep -v "<" text.xml |grep -v ">" |./xm1
1 Like