[TriLUG] grep'ing for multiple targets
Engle, Victor
Victor.Engle at netapp.com
Fri Oct 26 09:28:15 EDT 2007
>
> I need to grep for a couple of targets in a file eg in /proc/meminfo
>
> MemTotal: 772571936 kB
> MemFree: 291853936 kB
> Buffers: 125296 kB
How about egrep...
egrep 'MemTotal|MemFree|Buffers|Cached|SwapTotal|SwapFree'
/proc/meminfo
Regards,
Vic
> -----Original Message-----
> From: Joseph Mack NA3T [mailto:jmack at wm7d.net]
> Sent: Friday, October 26, 2007 9:22 AM
> To: trilug at trilug.org
> Subject: [TriLUG] grep'ing for multiple targets
>
> I need to grep for a couple of targets in a file eg in /proc/meminfo
>
> MemTotal: 772571936 kB
> MemFree: 291853936 kB
> Buffers: 125296 kB
> Cached: 378449152 kB
> SwapCached: 211888 kB
> Active: 324410928 kB
> Inactive: 145250592 kB
> HighTotal: 0 kB
> HighFree: 0 kB
> LowTotal: 772571936 kB
> LowFree: 291853936 kB
> SwapTotal: 303183680 kB
> SwapFree: 302166128 kB
> Dirty: 15505472 kB
> Writeback: 32800 kB
> Mapped: 89034896 kB
> Slab: 8205376 kB
> CommitLimit: 689469648 kB
> Committed_AS: 108303456 kB
> PageTables: 135984 kB
> VmallocTotal: 137080408512 kB
> VmallocUsed: 1971280 kB
> VmallocChunk: 137078436112 kB
> HugePages_Total: 0
> HugePages_Free: 0
> HugePages_Rsvd: 0
> Hugepagesize: 262144 kB
>
> I'd like to retreive say MemTotal, MemFree, Buffers, Cached,
> SwapTotal, SwapFree.
>
> I'd like to do this in one pass (rather than 6 passes).
> Currently I do something like
>
> awk '{print $2}' | xargs | awk '{print $1 ..linenumber_of_variable }'
>
> It turns out that the position in this list of a variable
> (say SwapTotal) varies for different 2.6 kernels, so I can't
> look for a variable by position (unless I have a case
> statement for each kernel).
>
> Is there a way to retrieve the lines with the above variables
> in one pass?
>
> Thanks Joe
>
> --
> Joseph Mack NA3T EME(B,D), FM05lw North Carolina jmack (at)
> wm7d (dot) net - azimuthal equidistant map generator at
> http://www.wm7d.net/azproj.shtml Homepage
> http://www.austintek.com/ It's GNU/Linux!
> --
> TriLUG mailing list :
> http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ : http://trilug.org/faq/ TriLUG
> Member Services FAQ : http://members.trilug.org/services_faq/
>
More information about the TriLUG
mailing list