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
  • 37,241
  • 25
  • 195
  • 267
user1929905
  • 389
  • 3
  • 9
  • 25

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
  • 266,786
  • 75
  • 396
  • 414