how make float to integer in awk

Truncate it using the int function:

print $1, $2, int( variable );

To keep exactly same spacing and everything:

awk -F ' ' '{print $1"     "$2"   "int($3)}' data.lst

this trims, does not round, so 4.9 will become 4.

A dirty way is to use the point as field separator:

awk -F '.' '{print $1}' data.lst

Input:

Bama     2   5
Bama     2   5.001
Bama     2   5.002
Bama     2   5.003
Bama     2   5.004
Bama     2   6
Bama     2   6.003
Bama     2   6.004
Bama     2   4.905

Output in either case:

Bama     2   5
Bama     2   5
Bama     2   5
Bama     2   5
Bama     2   5
Bama     2   6
Bama     2   6
Bama     2   6
Bama     2   4

Tags:

Awk