The rest of the example demonstrates how to store a 2 dimensional associative (named) array and iteratively print it after all files are processed
Code: Select all
#useage: status [Options]
#Options
#Name:State:Tgid:Pid:PPid:TracerPid:Uid:Gid:FDSize:Groups:VmPeak
#VmSize:VmLck:VmPin:VmHWM:VmRSS:VmData:VmStk:VmExe
#VmLib:VmPTE:VmSwap:Threads:SigQ:SigPnd:ShdPnd:SigBlk:SigIgn
#SigCgt:CapInh:CapPrm:CapEff:CapBnd:Seccomp:Cpus_allowed
#Cpus_allowed_list:voluntary_ctxt_switches:nonvoluntary_ctxt_switches
status(){
echo $@ | awk 'BEGIN{FN=0}
FNR==1{FN++}
FN==1{
argc=NF
for(j=0;j<NF;j++){
argv[j]=$(j+1)
field[FN][$(j+1)]=$(j+1)
}
}
FN>1{
title=substr($1,0,length($1)-1)
$1=""
field[FN][title]=$0
}
END{
for(i=1;i<FN;i++){
for(j=0;j<argc;j++){
printf "%-20s\t", field[i][argv[j]]
}
printf "\n"
}
}
' - /proc/*/status
}
Code: Select all
awk 'BEGIN{RS="\0"}{print}' /proc/1/environ