具有以下文件:
<tr class="in">
<th scope="row">In</th>
<td>1.2 kB/s (0.0%)</td>
<td>8.3 kB/s (0.0%) </td>
<td>3.2 kB/s (0.0%) </td>
</tr>
<tr class="out">
<th scope="row">Out</th>
<td>6.7 kB/s (0.6%) </td>
<td>4.2 kB/s (0.1%) </td>
<td>1.5 kB/s (0.6%) </td>
</tr>
我想像这样获取每秒之间的值<td></td>
(并将其保存到文件中):
8.3
4.2
到目前为止我的代码:
# get the lines with <td> tags
cat tmp.txt | grep '<td>[0-9]*.[0-9]' > tmp2.txt
# delete whitespaces
sed -i 's/[\t ]//g' tmp2.txt
# remove <td> tag
cat tmp2.txt | sed "s/<td>//g" > tmp3.txt
# remove "kB/s (0.0%)"
cat tmp3.txt | sed "s/kB\/s\((.*)\)//g" > tmp4.txt
# remove </td> tag and save to traffic.txt
cat tmp4.txt | sed "s/<\/td>//g" > traffic.txt
#rm -R -f tmp*
我怎样才能以常见的方式做到这一点?这段代码真的很牛逼。。
提前致谢,马利