0

I want to slice the 5th column down to three decimal points and put it with first column.

Input

                 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

OutputFile

                 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

Command:

awk -F" " '$6>0 { print substr($6,1,5)}' filename| awk '{print "("$0")"}'
  • awk -F" " '$6>0 { print substr($6,1,5)}' filename – KHAN irfan Oct 10 '17 at 0:59
  • As you're using AWK in your comment, note that printf "%.3f", $6 actually cuts the field down to three decimal places, regardless of how many digits are before the point, unlike substr – Fox Oct 10 '17 at 1:17
  • I think you mean the 6th column - not the 5th column – fpmurphy Oct 10 '17 at 3:04
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.