设置小数点位数的格式

设置小数点位数的格式

我想将第五列切成小数点后三位,并将其与第一列放在一起。

输入

                 Accuracy Precision Recall F-measure      s.d
 bemkl_J_DIFP    0.6001   0.01545 0.4304   0.02984    0.016098
 bemkl_J_DI      0.6011   0.01390 0.3870   0.02684    0.013959
 bemkl_J_FP      0.4831   0.01424 0.3609   0.02740    0.015979

输出文件

                 Accuracy      Precision Recall   F-measure
bemkl_J_DIFP  0.6001(0.016)     0.01545   0.4304   0.02984
bemkl_J_DI    0.6011(0.013)     0.01390   0.3870   0.02684
bemkl_J_FP    0.4831(0.015)     0.01424   0.3609   0.02740

命令:

awk -F" " '$6>0 { print substr($6,1,5)}' filename| awk '{print "("$0")"}'

答案1

$ cat 1.awk
BEGIN { FS = " " ; }
NR == 1  { printf "%26s %16s %8s %11s\n", $1, $2, $3, $4 }
NR > 1   { printf "%-15s %s(%0.2g)      %s    %s    %s\n", $1, $2, $6, $3, $4, $5 }
$ awk -f 1.awk infile
                  Accuracy        Precision   Recall   F-measure
bemkl_J_DIFP    0.6001(0.016)      0.01545    0.4304    0.02984
bemkl_J_DI      0.6011(0.014)      0.01390    0.3870    0.02684
bemkl_J_FP      0.4831(0.016)      0.01424    0.3609    0.02740

相关内容