#! /bin/bash awk 'BEGIN{ total = 0; printf("SIZE RSS SHARED_CLEAN SHARED_DIRTY PRIVATE_CLEAN PRIVATE_DIRTY ") }{ if(NF >3){ if($2 ~ /[r-][w-][x-][ps]/){ if($6 =="") name = $1; else name = $6; } } while(getline) { if(NF >3){ if($2 ~ /[r-][w-][x-][ps]/){ if($6 =="") name = $1; else name = $6; } } if($1 ~ /^Size/){ size = $2; total += $2; } if($1 ~ /Rss/){ rss = $2; } if($1 ~ /Shared_Clean/){ shared_clean = $2; } if($1 ~ /Shared_Dirty/){ shared_dirty = $2; } if($1 ~ /Private_Clean/){ private_clean = $2; } if($1 ~ /Private_Dirty/){ private_dirty = $2; } if($1 ~ /VmFlags/){ printf("%d %d %d %d %d %d %s ",size,rss,shared_clean,shared_dirty,private_clean,private_dirty,name); size = 0; name = ""; rss = 0; shared_clean = 0; shared_dirty = 0; private_clean = 0; private_dirty = 0; continue; } } }END{ printf("====total: %d ", total); }' $1