Using AWK variables.

Hi all, I am new to the forum and Shell Script programming.

The problem is:
I need to do a script to search all system processes and show me hierarchical way the number of bytes occupied by each of the regions of the memory map of each process.

Today I got to show me the number of regions in the memory map, this I did just to check if it really is working on AWK, now I have not done is stored in 2 variables memory addresses that appear in the first chain MAPS each line of the file, I understand that the address is in hexadecimal format must subtract the address "minor" to "higher" but first change the string to uppercase divided into two variables (that I understand) and then perform the calculation for show me now if I need hehe happy Bytes

Here the public part of the file MAPS:

00110000-00126000 r-xp 00000000 08:01 8051 /usr/lib/libnssutil3.so
00126000-00129000 r--p 00015000 08:01 8051 /usr/lib/libnssutil3.so
00129000-0012a000 rw-p 00018000 08:01 8051 /usr/lib/libnssutil3.so
0012a000-0012d000 r-xp 00000000 08:01 7711 /usr/lib/libgmodule-2.0.so.0.2200.2
0012d000-0012e000 r--p 00002000 08:01 7711 /usr/lib/libgmodule-2.0.so.0.2200.2 

The script is as follows:

#!/bin/sh
#!/bin/bash

filtrado()
{
RES=0
echo "PROCESS $n"
cat /proc/"$n"/maps |sed 's/-/ /' | awk 'END {print "TOTAL:",NR;}' 

awk '$2~/[p]/{ RES=RES+1;};END{print " PRIVATES:",RES;}' /proc/"$n"/maps

awk '$2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " WITH SUPPORT:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " MODIFIABLE:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " EXECUTABLE:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps

awk '$5!~/[1-9]/ && $2~/[p]/ {RES=RES+1;};END{print " ANONYMOUS:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " MODIFIABLE:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " EXECUTABLE:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " ONLY READ:",RES;}' /proc/"$n"/maps

awk '$2~//{ RES=RES+1;};END{print " SHARED:",RES;}' /proc/"$n"/maps

awk '$2~// && $4~/[1]/ {RES=RES+1;};END{print " WITH SUPPORT:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~// && $4~/[1]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~// && $4~/[1]/ {RES=RES+1;};END{print " EXECUTABLE:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~// && $4~/[1]/ {RES=RES+1;};END{print " ONLY READ:",RES;}' /proc/"$n"/maps

awk '$5!~/[1-9]/ && $2~// {RES=RES+1;};END{print " ANONIMOS:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~// && $5!~/[1-9]/ {RES=RES+1;};END{print " MODIFIABLE:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~// && $5!~/[1-9]/ {RES=RES+1;};END{print " EXECUTABLE:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~// && $5!~/[1-9]/ {RES=RES+1;};END{print " ONLY READ:",RES;}' /proc/"$n"/maps

echo " "

}

clear
for n in `seq 1 10000`;
do
m=/proc/$n/maps
if [ -f $m ]; then
filtrado $n
fi
done
exit

thank you very much guys :b:

Please provide a sample i/p and the expected o/p.

Excuse me, but do you mean by i / p & o / p.

?

He meant input and output