我只是给出一部分庞大的xml文件
<caldata chopper="on" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">4.00000000e+04</c1>
<c2 unit="V/(nT*Hz)">8.35950000e-06</c2>
<c3 unit="deg">-1.17930000e+02</c3>
</caldata>
<caldata chopper="on" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">5.55810000e+04</c1>
<c2 unit="V/(nT*Hz)">4.43400000e-06</c2>
<c3 unit="deg">-1.58280000e+02</c3>
</caldata>
<caldata chopper="on" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">6.00000000e+04</c1>
<c2 unit="V/(nT*Hz)">3.63180000e-06</c2>
<c3 unit="deg">-1.67340000e+02</c3>
</caldata>
<caldata chopper="off" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">4.00000000e-01</c1>
<c2 unit="V/(nT*Hz)">1.07140000e-02</c2>
<c3 unit="deg">1.48080000e+02</c3>
</caldata>
<caldata chopper="off" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">5.55800000e-01</c1>
<c2 unit="V/(nT*Hz)">1.33250000e-02</c2>
<c3 unit="deg">1.39110000e+02</c3>
</caldata>
<caldata chopper="off" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">7.72300000e-01</c1>
<c2 unit="V/(nT*Hz)">1.57750000e-02</c2>
<c3 unit="deg">1.29560000e+02</c3>我试过这样做
grep '<c1 unit="Hz"' *.xml | cut -f2 -d">"|cut -f1 -d"<"我真正想要的是只在caldata chopper="off"时输出,并将输出保存到文件中。怎么做?
发布于 2016-06-29 20:01:37
这样做可以:
cat file.xml | awk '/chopper="off"/,/calcdata/{print}' | grep 'unit="Hz"' | sed 's/^.*">//;s/<.*$//'第一个命令(awk)只接受包含chopper="off"的块。第二个命令(grep)只接受你想要的数字行。第三个命令(sed)从行中获取数字。
https://stackoverflow.com/questions/38108795
复制相似问题