Tuesday, April 29, 2008

xml processing using sed - post1


$ cat studentinfo.xml
<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>SID469</StudentId>
<ClassId>21</ClassId>
<Location>AA</Location>
</Student>
<Student>
<StudentId>CSI150</StudentId>
<ClassId>71</ClassId>
<Location>AX</Location>
</Student>
<Student>
<StudentId>PIA687</StudentId>
<ClassId>1</ClassId>
<Location>AP</Location>
</Student>
...
...
</StudentInfo>

Purpose:
--------------
Make all ClassId's to "2"

Solution:
--------------
$ sed -e 's/\(ClassId\)\([0-9]*\).*\(\/ClassId\)/\1>'2'<\3/' studentinfo.xml > studentinfo.xml.bak

Now:
-----------
$ cat studentinfo.xml.bak
<?xml version="1.0" encoding="UTF-8"?>
<StudentInfo Version="1">
<Student>
<StudentId>SID469</StudentId>
<ClassId>2</ClassId>
<Location>AA</Location>
</Student>
<Student>
<StudentId>CSI150</StudentId>
<ClassId>2</ClassId>
<Location>AX</Location>
</Student>
<Student>
<StudentId>PIA687</StudentId>
<ClassId>2</ClassId>
<Location>AP</Location>
</Student>
...
...
</StudentInfo>

No comments:

© Jadu Saikia www.UNIXCL.com