There are several days' worth of files retrieved from vmstat-a5.
In order to calculate the average memory usage, I would like to know the average usage of Free, but when I add it with awk, it overflows with digits and it doesn't work.
In the shell script,
I am.
VAR=`awk'{m+=$4}END{printm/NR;}'${myfile}`
Please let me know if there is a good way.
shellscript awk
awk'{a+=($4-a)/NR}END {printa}'
To avoid displaying exponential notation (scientific notation), you can use printf
to specify the format.
printf "%d\n",m;
You can also decide in advance which format print
should be used by OFMT
.
BEGIN {OFMT="%d"}
The questioner's case this time was different, but
When calculating the average of huge data, the calculation method that accumulates into one floating-point number is inevitably a problem of accuracy.Even with the calculation method, it is easy to notice problems such as not reflecting the data in the second half.
In this case, it is easy to use something that can perform arbitrary precision operations (multiple-length operations) as others commented.
There is also a way to calculate the average after calculating the average for each period of time.
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
611 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.