http://www.unix-center.net/bbs/viewthread.php?tid=2404
shell xml
2011-03-22 18:02
xmlparser.sh
#!/bin/bash
declare -a ids declare -a artists declare -a titles tmp=`sed -n -e 's/<lrc //' -e 's/><//lrc>//p' $1 | sed -e 's/id="//' -e 's/artist="//' -e 's/title="//' -e 's/"//g'`
lrc=($(echo $tmp)) for((i=0, j=0; i<${#lrc[*]}; i++, j++)) do #echo "${lrc[i]}--${lrc[++i]}--${lrc[++i]}" ids[j]=${lrc[i]} artists[j]=${lrc[++i]} titles[j]=${lrc[++i]} done
for((k=0; k<${#ids[*]}; k++)) do echo "id: ${ids[k]}--artist: ${artists[k]}--title: ${titles[k]}" done
test.xml
<?xml version="1.0" encoding="UTF-8" ?> <result> <lrc id="189296" artist="陶晶莹" title="太委屈"></lrc> <lrc id="1243" artist="xxx" title="vvv"></lrc> </result>
./xmlparser.sh test.xml
|