xml - bash script for replace text from two file in one -
i have 2 file xml; en.xml , it.xml
in default file language en.xml have structure
<string key="city not set"> <tr lang="en"> city not set </tr>
in file it.xml have:
<string key="città non è impostato"> <tr lang="it"> </tr>
in way can extract data it.xml , put in en.xml ?
from en.xml need string key
<string key="city not set">
in second file it.xml need change:
<string key="città non è impostato">
in :
<tr lang="it"> città non è impostato </tr>
my goal obtain final result:
<string key="city not set"> <tr lang="it"> città non è impostato </tr>
i hope clear.
i use parse xml:
get_data () { local tag=$1 local xml=$2 # find tag in xml, convert tabs spaces, remove leading spaces, remove tag. grep $tag $xml | \ tr '\011' '\040' | \ sed -e 's/^[ ]*//' \ -e 's/^<.*>\([^<].*\)<.*>$/\1/' } get_data \<tag_name\> filename.xml | tee output.txt cat output.txt
and add bunch of if else commands relating input, prompts , stuff, , you've got functionable xml parser.
i use curl command parse xml feeds newspapers, , personal favourite rssmaker.
also, here's the source.
have fun!
Comments
Post a Comment