I want to use awk only to calculate memory usage from /proc/meminfo file. I tried to do awk ‘NR==1 || NR==2 {print $2}
it prints the 2nd column in the first 2 lines ( MemTotal and MemFree ) but I want to output the difference. Do you have any ideas?
Solution
This should work:
awk 'NR==1{T=$2} NR==2{F=$2; print(T-F); exit}' /proc/meminfo
Answered By — Mark Setchell
Answer Checked By — Timothy Miller (FixIt Admin)
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0