1

I have a MyFile.xml whose contents are as below

<root>
    <Main>
            <someothertag>..</someothertag>
        <Amt Ccy="EUR">13</Amt>
    </Main>
                .
                .
                .
                some other tags
    <Main>
          <someothertag>..</someothertag>
             <Amt Ccy="SGD">10</Amt>
    </Main>
    <another>
      <Amt Ccy="EUR">10</Amt>
     </another>
</root>

I have script file whose contents are as below

result = `awk '/<Main>/ { f=1 } f && /Amt/ { split($0,a,/[<>]/); s+=a[3] } /<\/Main>/ { f=0 } END {print  s }' MyFile.xml`
echo "The result is " $result

But i am getting output as

result: 0653-690 Cannot open =.
result: 0653-690 Cannot open 23.
The result is

My Expected output is

The result is 23
Cœur
  • 34,719
  • 24
  • 185
  • 251
user1929905
  • 409
  • 2
  • 7
  • 23

1 Answers1

0

When assigning variables there should be no spaces on either side of the =.

Change to:

result=`awk '/<Main>/ { f=1 } f && /Amt/ { split($0,a,/[<>]/); s+=a[3] } /<\/Main>/ { f=0 } END {print  s }' MyFile.xml`
dogbane
  • 254,755
  • 72
  • 386
  • 405