Search code examples
linuxsedcsh

how to read xml file in linux


I have one xml file as below, I need "en" using some unix command.

        <void method="put">
            <string>LANGUAGE</string>
            <string>en</string>
        </void>    

using below command (got from some link in google),

sed -n '/string/{s/.*<string>//;s/<\/string.*//;p;}' Locale.xml

I am getting output as

LANGUAGE
en

so I used

sed -n '/string/{s/.*<string>//;s/<\/string.*//;p;}' Locale.xml | tail -1

But is there any option in sed by which I can get second value only?


Solution

  • You can use this sed,

    sed -n '/LANGUAGE/{N; s/.*<string>\(.*\)<\/string>.*/\1/p; }' Locale.xml