使用bash搜索和替换输出

时间:2014-01-09 09:32:30

标签: bash

这是我的bash代码:

  paste - - - - - - - < /home/secmgr/attmrms1/data_tripwire1.txt | while read -a values; do
    mean=$(arith_mean "${values[@]}")
    sd=$(sd $mean "${values[@]}")
    echo "${values[@]} $mean $sd"
    echo "<tr><td>Baseline<td>Standard deviation=$sd<td>"${values[@]} $sd"</tr>" >> $HTML
    done | column -t

我希望输出如下:

Month   CBS     GFS      HR     HR         Payroll   INCV 
        cb2db1  gfs2db1 hr2web1 hrm2db1   hrm2db1a   incv2svr1 
2013-07 85      76      12      28        26          4 
2013-08 58      103     18      6         24         18 
2013-09 54      110     11      14        25         17 
2013-10 108     129     17      8         23         18 
2013-11 52      137     12      8         21         30 
2013-12 18      84      6       0         13         13 
2014-01 8       16      1       0         9           3
*Standard
deviation
(7mths)  31.172   35.559    5.248  8.935  5.799    8.580 
* Mean
(7mths) 54.428  94.285   11.142 9.142  20.285   14.714

我现在面临的问题是输出如下所示:

Month   CBS     GFS      HR     HR         Payroll   INCV 
        cb2db1  gfs2db1 hr2web1 hrm2db1   hrm2db1a   incv2svr1 
2013-07 85      76      12      28        26          4 
2013-08 58      103     18      6         24         18 
2013-09 54      110     11      14        25         17 
2013-10 108     129     17      8         23         18 
2013-11 52      137     12      8         21         30 
2013-12 18      84      6       0         13         13 
2014-01 8       16      1       0         9           3
Baseline Standard deviation=31.712 
Baseline Standard deviation=35.559 
Baseline Standard deviation=5.248 
Baseline Standard deviation=8.935 
Baseline Standard deviation=5.799 
Baseline Standard deviation=8.580 

我希望Baseline Standard deviation全部在一行而不是分开。像这样:

Baseline Standard deviation=31.712  35.559  5.248  8.935  5.799  8.580 

1 个答案:

答案 0 :(得分:1)

这是一种方式:

echo "Standard Deviation"
echo "<tr><td>Standard Deviation</td></tr>" >> $HTML
echo "<tr>" >> $HTML
paste - - - - - - - < /home/secmgr/attmrms1/data_tripwire1.txt | while read -a values; do
    mean=$(arith_mean "${values[@]}")
    sd=$(sd $mean "${values[@]}")
    printf "%s " $sd
    echo "<td>$sd</td>" >> $HTML
    done | column -t
printf "\n";
echo "</tr>" >> $HTML

echo "Mean"
echo "<tr><td>Mean</td></tr>" >> $HTML
echo "<tr>" >> $HTML
paste - - - - - - - < /home/secmgr/attmrms1/data_tripwire1.txt | while read -a values; do
    mean=$(arith_mean "${values[@]}")
    printf "%s " $mean
    echo "<td>$mean</td>" >> $HTML
    done | column -t
printf "\n";
echo "</tr>" >> $HTML