Get output of fields starting from 2nd line

Hi All,

I am using the following command in Linux:

 
sar -r 30 3
Linux 2.6.18-194.3.1.7.3.el5xen  02/07/2013

02:55:47 PM kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused  kbswpcad
02:56:17 PM 128646024  22348920     14.80    230232  15575860  75497464         0      0.00         0
02:56:47 PM 128646188  22348756     14.80    230244  15576116  75497464         0      0.00         0
02:57:17 PM 128646676  22348268     14.80    230248  15576160  75497464         0      0.00         0
Average:    128646296  22348648     14.80    230241  15576045  75497464         0      0.00         0
-bash-3.2$

I have tried using the following command to get the desired output but somehow not getting it. %memused field is blank

 
-bash-3.2$ sar -r 1 3 | grep -v Average | grep -v Linux | cut -d' ' -f1,2,6

12:57:57 PM %memused
12:57:58 PM
12:57:59 PM
12:58:00 PM
-bash-3.2$

From the above output, I need to get the following output onwards.

Output should look as below( Need only the values and not the columns to be displayed):

 
02:55:47 PM    %memused 
02:56:17 PM      14.80    
02:56:47 PM      14.80    
02:57:17 PM      14.80    

Thanks for your time!

Regards,
a1_win

sar -r 1 3 | awk '/^[0-9]/ {print $1,$2,$5}'
02:55:47 PM %memused
02:56:17 PM 14.80
02:56:47 PM 14.80
02:57:17 PM 14.80

PS remove the / in your start code tag

bash has a nice feature. You declare a simple array variable 'typedef -a myarray' and then 'while read -a myarray' and the fields are in the array for each line. Awk does that sort of thing natively.

BTW, free memory is a worthless spec in a VM system. That stat is left over from the old days of memory resident everything. delta page faults is more interesting, and load (cpu avg queue depth).

Instead of trying to filter away everything you do not want it is sometimes easier to specify what you do want: ever line where "<time> PM " is followed by a digit, not a letter, right?

grep '^[0-2][0-9]:[0-6][0-9]:[0-6][0-9] PM [0-9]'

Should filter all the lines you are interested in. As you use "cut" afterwards to dissect the lines you can combine this regexp and the "cut"ting into an awk- or sed-script, like Jotne already did - alas, his filter regexp is wrong:

sar -r 1 3 | awk '/^[0-2][0-9]:[0-6][0-9]:[0-6][0-9] PM [0-9]/ {print $1,$2,$5}'

I have to agree with DGPickett: you probably are extracting not particular meaningful numbers and might want to give your methodology a second thought.

I hope this helps.

bakunin

Thanks this has helped!

Regards,
a1_win