I have an xml file that has numbers within tags. Ex)
<REC_CNT>25000</REC_CNT>
<REC_CNT>25000</REC_CNT>
<REC_CNT>25000</REC_CNT>
<REC_CNT>11767</REC_CNT>
I need to get the sum of these numbers while at the same time the final output has to still have the tags around it.
<REC_CNT>86767</REC_CNT>
I've used awk already to remove the tags and add the numbers but that is not what I'm looking for. What I'm doing is a replace and if I only get the number then the replace will also replace every other number in that file that it is equal to, not just the REC_CNT... any input?
cat $pocfiles | grep '<REC_CNT>' | awk 'BEGIN {FS="<REC_CNT>"} {print substr($2,0)}' | awk 'BEGIN {FS="<"} {print substr($1,0)}' | awk '{SUM += $1} END {print SUM}'I ended up removing the tags, added the numbers, and reformatted my sed statement to only replace the first instance of the number: sed -i "0,/$oldcount/s//$newcount/" Thanks for the help!