I have multiple xml files and I would like to fetch values from them, and write them in a separate csv/text/excel file row by row.
I tried the grep command below:
grep -e \<r p\> Inputfilename | sed 's/<[^>]*>//g' | awk '{ print $2 }' | awk '{ for (i=1;i<=NF;i++ ) printf $i " " }' >> Output.txt
But this command writes all the values in a single line. I am a newbie so I am not sure how to separate the values row wise.
Here is a sample input file:
<measType p="1">Used NonHeap Mem MB</measType>
<measType p="2">Online CPU Usage %</measType>
<measType p="3">Used Physical Mem %</measType>
<measType p="4">Used Physical Mem MB</measType>
<measType p="5">Used Heap Mem %</measType>
<measType p="6">Used Tenured Gen MB</measType>
<measType p="7">Used Survivor Space MB</measType>
<measType p="8">Used NonHeap Mem %</measType>
<measType p="9">Total CPU Usage %</measType>
<measType p="10">Used Eden Space MB</measType>
<measType p="11">Used Heap Mem MB</measType>
<measValue measObjLdn="">
<r p="1">48.361183166503906</r>
<r p="2">0.008397036232054234</r>
<r p="3">4.5677</r>
<r p="4">34425.0</r>
<r p="5">68.05066879841843</r>
<r p="6">410.58392333984375</r>
<r p="7">22.375</r>
<r p="8">93.67783664213832</r>
<r p="9">0.028054807427357</r>
<r p="10">169.9580841064453</r>
<r p="11">602.8837356567383</r>
</measValue>
The output I got from the above command, for this input, is:
48.361183166503906 0.008397036232054234 4.5677 34425.0 68.05066879841843 410.58392333984375 22.375 93.67783664213832 0.028054807427357 169.9580841064453 602.883735656738
When I run this command for multiple files it yields something like this:
48.361183166503906 0.008397036232054234 4.5677 34425.0 68.05066879841843 410.58392333984375 22.375 93.67783664213832 0.028054807427357 169.9580841064453 602.8837356567383 48.377540588378906 0.008116667158901691 5.73992 33834.0 10.798112742450364 42.10478973388672 22.375 93.70952172083081 0.021666161122907 31.18431854248047 95.66410827636719 58.068382263183594 3.406280755996704 6.46515 34405.0 56.60833858273274 903.4959945678711 16.5166015625 94.90236120642875 7.068469741716277 39.66230773925781 959.4206771850586
But I want the command result to be:
48.361183166503906 0.008397036232054234 4.5677 34425.0 68.05066879841843 410.58392333984375 22.375 93.67783664213832 0.028054807427357 169.9580841064453 602.8837356567383
48.377540588378906 0.008116667158901691 5.73992 33834.0 10.798112742450364 42.10478973388672 22.375 93.70952172083081 0.021666161122907 31.18431854248047 95.66410827636719
58.068382263183594 3.406280755996704 6.46515 34405.0 56.60833858273274 903.4959945678711 16.5166015625 94.90236120642875 7.068469741716277 39.66230773925781 959.4206771850586
Please assist me. Thanks in advance!