[sgeorge@sgeorge-ld staCK]$ cat xml
<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>100</Amount>
<Location>AA</Location>
</Student>'
'<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>100</Amount>
<Location>AA</Location>
</Student>'
'<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>100</Amount>
<Location>AA</Location>
</Student>
[sgeorge@sgeorge-ld staCK]$ OLDIFS=$IFS; IFS=$'\n'; COUNT=1; for i in `cat xml` ; do echo $i | sed "s/<Amount>.*<\/Amount>/<Amount>"$COUNT"<\/Amount>/g" && ((COUNT++)) ; done ; IFS=$OLDIFS
<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>6</Amount>
<Location>AA</Location>
</Student>'
'<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>14</Amount>
<Location>AA</Location>
</Student>'
'<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>22</Amount>
<Location>AA</Location>
</Student>
または (Amount に実際のカスタム値が必要な場合)、次のようにします。
[sgeorge@sgeorge-ld staCK]$ cat amount.txt
121213424525
1213125435
1313145357460
988783784332
82990190231932
[sgeorge@sgeorge-ld staCK]$ OLDIFS=$IFS; IFS=$'\n'; COUNT=1; for i in `cat xml` ; do echo $i | grep '<Amount>' >/dev/null && AMT=$(tail -1 amount.txt) && sed -i "/^$AMT$/d" amount.txt && echo $i | sed "s/<Amount>.*<\/Amount>/<Amount>"$AMT"<\/Amount>/g" || echo $i ; done ; IFS=$OLDIFS
<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>82990190231932</Amount>
<Location>AA</Location>
</Student>'
'<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>988783784332</Amount>
<Location>AA</Location>
</Student>'
'<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>INS469</StudentId>
<ClassId>21</ClassId>
<Amount>1313145357460</Amount>
<Location>AA</Location>
</Student>
編集
OLDIFS=$IFS; IFS=$'\n'; COUNT=1; for i in `cat xml` ; do echo $i | grep '<Amount>' >/dev/null && AMT=$(tail -1 amount.txt) && sed -i "/^$AMT$/d" amount.txt && echo $i | sed "s/<Amount>.*<\/Amount>/<Amount>"$AMT"<\/Amount>/g" || echo $i ; done > /tmp/xml_output.xml; IFS=$OLDIFS