grep avm line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep avm line
# 1  
Old 07-20-2011
grep avm line

Greetings:

I have vmstat output, and need to grep the value of avm, which is 6205376 for this example.

Code:
root@:/>>vmstat 1 1

System configuration: lcpu=8 mem=20480MB

kthr    memory              page              faults        cpu    
----- ----------- ------------------------ ------------ -----------
 r  b   avm   fre  re  pi  po  fr   sr  cy  in   sy  cs us sy id wa
 7  0 6205376  5184   0   0   0   0    0   0  30 92615 16469 95  5  0  0

I need a help on two things please.

1) the memory usage calculation = 6205376 / 256 = 24,239.75 MB

2) the memory usage % (the value from 1 / the total mem) = 24,239.75 / 20480 = 118.35%

Thank you so much for your help.

Last edited by pludi; 07-20-2011 at 12:32 PM..
# 2  
Old 07-20-2011
This is little more, you can use any cols.
Code:
#!/usr/bin/ksh

# set columns value into variable
set_val()
{
        unset vals # clear value array
        vals=($*)  # set values into array

        nflds=${#flds[*]}   # num of fields (headerline=columnnames)

        fld=0
        while ((fld<nflds))
        do
                varname=${flds[$fld]}    # colname
                eval $varname=\"\"       # set "" 1st, if it s not in this line
                eval $varname=\""${vals[$fld]}"\"    # set value fot variable
                ((fld+=1))
        done

}

# parse mem value
readmem()
{
        data="$*"
        lastf=${data##*=}   # last fld using delim =
        lastf=${lastf/MB/}   # remove MB
        echo "$lastf"
}


#MAIN
LANG=C    # desimal delimiter = .
header=0  # set 1 after columnnames has readed
data=0      # data started (--- ---- ---- ---- ...)
mem=0
# floating using 2 decimals
typeset -F2 mem1 mem2 mem


#testdata
echo "System configuration: lcpu=8 mem=20480MB

kthr    memory              page              faults        cpu
----- ----------- ------------------------ ------------ -----------
 r  b   avm   fre  re  pi  po  fr   sr  cy  in   sy  cs us sy id wa
 7  0 6205376  5184   0   0   0   0    0   0  30 92615 16469 95  5  0  0" | while read line
do
        case "$line" in
                "System configuration:"*) mem=$(readmem "$line") && continue ;;
                "----"*) data=1 ; continue ;; # data start
        esac
        (( data == 0 )) && continue # no data yet
        (( header == 0 )) && flds=($line) && header=1 && continue # headerline
        set_val $line
        echo "avm:$avm"
        (( mem1=avm/256.00))
        (( mem2=mem1/mem*100.00 ))
        echo Mem:$mem Avm:$avm $mem1 $mem2  - (fre:$fre)
done


Last edited by kshji; 07-20-2011 at 03:18 PM..
# 3  
Old 07-21-2011
Thank you so much
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep -q not works with multiples grep in same line

Hi, I'm trying to make a grep to see if exists occurrences with a sentence like these: grep -qi "message" file0 | grep -i $date | grep -vi "exception" echo $? 1 If I execute without -q modifier I can find occurrences. Someone could help me please? Thanks and sorry for my English! (1 Reply)
Discussion started by: mierdatuti
1 Replies

2. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

3. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

4. Shell Programming and Scripting

How to Grep than scan line below grep pattern

Hello Colleagues, I have a file that looks like below. 6-12731913-12731913 9230760143480 410018547148230 20131002193434+0500 20131002193434+0500 ;20131002T161031000-10.50.241.21-21912131-1419034760, ver: 0 20131009 92220056296730 CC0P abc Core_Context_R1A SMS 6-12726796-12726796... (14 Replies)
Discussion started by: umarsatti
14 Replies

5. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

6. Shell Programming and Scripting

Sed or Grep to delete line containing patter plus extra line

I'm new to using sed and grep commands, but have found them extremely useful. However I am having a hard time figuring this one out: Delete every line containing the word CEN and the next line as well. ie. test.txt blue 324 CEN green red blue 324 CEN green red blue to produce:... (2 Replies)
Discussion started by: rocketman88
2 Replies

7. Shell Programming and Scripting

cat file1 read line-per-line then grep -A 15 lines down in fileb

STEP 1 # Set variable FILE=/tmp/mainfile SEARCHFILE =/tmp/searchfile # THIS IS THE MAIN FILE. cat /tmp/mainfile Interface Ethernet0/0 "outside", is up, line protocol is up Hardware is i82546GB rev03, BW 100 Mbps Full-Duplex(Full-duplex), 100 Mbps(100 Mbps) MAC address... (6 Replies)
Discussion started by: irongeekio
6 Replies

8. UNIX for Dummies Questions & Answers

Grep or other ways to output line above and/or below searched line

Hi all, Would like to know how I could search for a string 'xyz' but have the output show the line plus the line above and/or below all lines found. eg. search for xyz from file containing: abc 12345 asdf xyz asdfds wwwww kjkjkj ppppp kkkxyz eeee zzzzz and the output to... (2 Replies)
Discussion started by: sammac
2 Replies
Login or Register to Ask a Question