I have the following dataset (all positive values)
Input file
1 2.3456
1 5.02
2 3.9763333
2 0.123
I would like to truncate the numbers in the second column and discard its non-integer part.
How would one do it in awk?
Desired output file
1 2
1 5
2 3
2 0
Thanks for your help.
try the int() function
awk '{$2=int($2)}1' file
awk '{printf("%d %d\n"), $1, $2;}' inputFileName
Since you want to truncate rather than round, use %d
instead of %0.f
:
awk '{printf "%s %d\n", $1, $2}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With