awk解析xml

复制代码
?xml version="1.0"?>
<system>
   <machine name="web01" >
         <server name="log_collect">
            <processes>1processes>
            <threads>1threads>
            <options>-t1 options>
            <desc/>
         server>
         <server name="dcs_fresh">
            <processes>1processes>
            <threads>1threads>
            <options>-a192.168.1.1options>
            <desc/>
         server>
   machine>
   <machine name="web02">
         <server name="log_collect">
            <processes>2processes>
            <threads>2threads>
            <options>-t2 options>
            <desc/>
         server>
         <server name="dcs_fresh">
            <processes>2processes>
            <threads>2threads>
            <options>-a192.168.1.2options>
            <desc/>
         server>
   machine>
复制代码
BEGIN{FS="[<>\"]"}
/machine name/{a=$3}
/server name/{b=$3}
/>.*" "$3:$3}
/<\/server>/{print a" "b" "c;b=0;c=0}
[sunsweet@ubuntu:~/shell/monitor]>>awk -f xml.awk xml
web01 log_collect 1 1 -t1 
web01 dcs_fresh 1 1 -a192.168.1.1
web02 log_collect 2 2 -t2 
web02 dcs_fresh 2 2 -a192.168.1.2

 

你可能感兴趣的:(Lua/Awk/Python)