Awk: Difference between revisions

From Hackepedia
Jump to navigationJump to search
No edit summary
 
mNo edit summary
Line 1: Line 1:
I wanted to find out how much resident memory [[xfce4]] was using on my system, and it appears most xfce applications start with "xf":
I wanted to find out how much resident memory [[xfce4]] was using on my system, and it appears most xfce applications start with "xf":
  $ ps auwx | grep xf | awk '{print $5}'
  $ ps auwx | awk '/xf/{print $5}'
  15924
  15924
  14668
  14668
Line 11: Line 11:


I wanted to use awk to add the results together instead of doing it manually:
I wanted to use awk to add the results together instead of doing it manually:
  $ ps auwx | grep xf | awk '{ tot += $5 } END { print tot }'
  $ ps auwx | awk '/xf/{ tot += $5 } END { print tot }'
  69108
  69108
''N.B.'' This can be misleading in the case of programs that use large amounts of shared memory (like java).

Revision as of 09:09, 14 December 2005

I wanted to find out how much resident memory xfce4 was using on my system, and it appears most xfce applications start with "xf":

$ ps auwx | awk '/xf/{print $5}'
15924
14668
11948
11764
12944
16264
1860


I wanted to use awk to add the results together instead of doing it manually:

$ ps auwx | awk '/xf/{ tot += $5 } END { print tot }'
69108

N.B. This can be misleading in the case of programs that use large amounts of shared memory (like java).