Home > Back-end >  reformatting data to nice format
reformatting data to nice format

Time:08-17

I have three columns of data that contain data as follows

26.77 12.477 -25 100
26.364 12.476 -20 100
26.372 11.47 -16 100
26.366 10.473 -10 100
26.158 10.472 -9 100
26.75 12.471 2 100

I want to reformat data to

26.770 12.477 -25 100
26.364 12.476 -20 100
26.372 11.470 -16 100
26.366 10.473 -10 100
26.158 10.472 -09 100
26.750 12.471  02 100

i tried below code but it did not work.

awk '{ printf("%.3g %.3g %.3g %.3g\n", $1, $2, $3, $4) }' in.dat

CodePudding user response:

The format you requested can be done with:

awk '{ printf("%.3f %.3f % 03.0f %.0f\n", $1, $2, $3, $4) }'

However I would just pipe it to column -t for "nice" format.

  • Related