I have collected vmstat data in a file . It gives details about free, buffer and cache .
SInce i’m interested in finding the memory usage , I should do the following computation for each line of vmstat output — USED=TOTAL – (FREE+BUFFER+CACHE) where TOTAL is the total RAM memory and USED is the instantaneous memory value.
TOTAL memory = 4042928 (4 GB)
My code is here
grep -v procs $1 | grep -v free | awk '{USED=4042928-$4-$5-$6;print $USED}' > test.dat
awk: program limit exceeded: maximum number of fields size=32767
FILENAME="-" FNR=1 NR=1
You should not be printing
$USEDfor a start, the variable inawkisUSED:What is most likely to be happening in your case is that you’re using an
awkwith that limitation of about 32000 fields per record.Because your fields
4,5and6are respectively25172,664and8520(from one of your comments), yourUSEDvalue becomes4042928-25172-664-8520or4008572.If you tried to print
USED, that’s what you’d get but, because you’re trying to print$USED, it thinks you want$4008572(field number 4008572) which is just a little bit beyond the 32000 range.Interestingly, if you have a lot more free memory, you wouldn’t get the error but you’d still get an erroneous value 🙂
By the way,
gawkdoesn’t have this limitation, it simply prints an empty field (see, for example, section 11.9 here).