2012-12-27 5 views
1

나는 그 내용이 다음과 같이됩니다 MyFile.xml이awk 명령 및 변수 할당

<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> 

나는 그 내용

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 

다음과 같습니다 그러나 내가

로 출력을 얻고 스크립트 파일이
result: 0653-690 Cannot open =. 
result: 0653-690 Cannot open 23. 
The result is 

내 예상 출력은

입니다.
The result is 23 
+0

http://stackoverflow.com/questions/2268104/basic-bash-script-variable-declaration-command-not-found/2268117#2268117 –

답변

0

변수를 할당 할 때는 =의 양쪽에 공백이 없어야합니다.

변경하려면 :

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

감사의가 완벽하게 작동 – user1929905