Math count %memory using awk

Hi expert,

i have log this:

Memory: 74410384
Memory: 75831176
Memory: 77961232
Memory: 77074656
Memory: 76086160
Memory: 77128592
Memory: 78045384
Memory: 76696040
Memory: 72401176
Memory: 72520016
Memory: 72137016
Memory: 73175832
Memory: 73034528
Memory: 71770736
Memory: 70629968
Memory: 1201871408
Memory: 1200533688
Memory: 1204072584
Memory: 1207242520
Memory: 1189510880
Memory: 1194879552
Memory: 1184069360
Memory: 1205724952
Memory: 1207634864
Memory: 1199368248
Memory: 1196559296
Memory: 1191823312
Memory: 1202758160
Memory: 1198021912
Memory: 1205363264

I want to count % memory with 2 digit after comma.

I try this but doesn't work

awk '{print $2/1024/1024/9787*100}' | bc | sed -re 's/([0-9]+\.[0-9]{2})[0-9]+/\1/g'

The results should be like this:

0.72
0.73
0.75
0.75
0.74
0.75
0.76
0.74
0.70
0.70
0.70
0.71
0.71
0.69
0.68
11.71
11.69
11.73
11.76
11.59
11.64
11.53
11.74
11.76
11.68
11.65
11.61
11.72
11.67
11.74

Thanks

expert,
Now that we see what 'you log' looks like, what your expert wants to see as output?

the output should be as above.

printf("%.2f\n", $3/1024/.....)

---------- Post updated at 10:07 PM ---------- Previous update was at 10:05 PM ----------

No bc, no sed - just awk

1 Like

For highest precision do the mult before the div

$2*100/1024/1024/9787

or force to floating-point

$2/1024.0/1024/9787*100
1 Like