original file :
a|||a 2 0.111111 a|||book 1 0.0555556 a|||is 2 0.111111
now i need to control third columns with 6 decimal space
after i tried awk {'print $1,$2; printf "%.6ft",$3'}
but the output is not what I want
result :
a|||a 2 0.111111 a|||book 1 0.055556 a|||is 2
that’s weird , how can I do that will just modify third columns
Advertisement
Answer
Your print()
is adding a newline character. Include your third field inside it, but formatted. Try with sprintf()
function, like:
awk '{print $1,$2, sprintf("%.6f", $3)}' infile
That yields:
a|||a 2 0.111111 a|||book 1 0.055556 a|||is 2 0.111111