如何在Linux中读取xml文件 [英] how to read xml file in linux
本文介绍了如何在Linux中读取xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个xml文件,如下所示,我需要使用一些unix命令来 en。
I have one xml file as below, I need "en" using some unix command.
<void method="put">
<string>LANGUAGE</string>
<string>en</string>
</void>
使用以下命令(从Google中的某些链接获取),
using below command (got from some link in google),
sed -n '/string/{s/.*<string>//;s/<\/string.*//;p;}' Locale.xml
我得到的输出为
LANGUAGE
en
所以我用了
sed -n '/string/{s/.*<string>//;s/<\/string.*//;p;}' Locale.xml | tail -1
但是sed中是否有我只能获得第二价值的选项?
But is there any option in sed by which I can get second value only?
推荐答案
您可以使用此 sed
,
sed -n '/LANGUAGE/{N; s/.*<string>\(.*\)<\/string>.*/\1/p; }' Locale.xml
这篇关于如何在Linux中读取xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文