I have a XML in which <Amt Ccy="EUR">3.1</Amt> tag repeats. This is under another tag <Main>. I need to sum all the values of <Amt Ccy=""> (Ccy may vary) coming under <Main> using awk and or sed command.
This will do the task for the sample file you posted:
awk '/Amt Ccy/ {sum+=$3} END {print sum}' FS="[<>]" file
It relies on the amount line NOT spanning several lines; there are solutions for that case in these forums.
And, be advised that summing up different currencies will almost certainly run you into trouble with the financial guys - awk offers ways to sum up into different curr. arrays. This is left for your exercise.
@RudiC: The User is looking to sum up the values which comes between <Main> tags
Yours will include the Amt in <another> tag, can you please re-edit it.
---------- Post updated at 03:36 AM ---------- Previous update was at 03:23 AM ----------
Unfortunately neither awk or sed are optimal tools for use with XML documents. You really need to use a stylesheet transformation language such as XSLT.