function getmem( x, f, res) { while ((cmd | getline x) > 0) { if (x ~ /gawk.*mem/) { split(x, f) if (f[2] ~ /gawk/) { res = f[1] break } } } close(cmd) return res } BEGIN { mom_version = "fubar" cmd = "ps -u $USER -o rss,command" base = getmem() } { gsub("\r","") ; gsub(/#.*$/,"") if (fixram==1) { if (mom_version !~ sprintf("%s",$1)) next } else if (mom_version !~ $1) next } END { printf "RSS per record = %.2f\n", (getmem()-base)/NR }