简体   繁体   中英

Search and replace output using bash

This is my bash code:

  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

I want the output to be like this:

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

The problem I'm facing now is that the output looks like the one shown below:

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 

I want the Baseline Standard deviation to be all in one single row and not separate. Something like this:

Baseline Standard deviation=31.712  35.559  5.248  8.935  5.799  8.580 

Here's one way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM