Shell script parse xml in linux

How to use shell script parse xml file. In this tutorial, I will use grep command, awk command and sed command Reading xml file extracting value in linux.

For example xml person file as below

How to extracting value Huu and Miranda  of <firstname> </firstname>

Use grep command

[huupv@huupv]$ grep -oP '(?<=<firstname>).*(?=</firstname)' person.xml

Use awk command

[huupv@huupv]$ awk -F "[><]" '/firstname/{print $3}' person.xml

Use sed command

[huupv@huupv]$ sed -n '/firstname/{s/.*<firstname>//;s/<\/firstname.*//;p;}' person.xml 
The result, Shell script parse xml in linux


Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install and configure zimbra multi server