Shell script grep help

Hey there, newbie question :

echo "::kmastat" | /usr/bin/mdb -k | grep Total | grep "kmem_*"
Total [kmem_msb] 17326080 432853 0
Total [kmem_va] 426508288 65458 0
Total [kmem_default] 704757760 1572001732 0
Total [kmem_tsb_default] 1277952 3027965 0
Total [segkmem_ppa] 3145728 23 0

I do this on a solaris box, as a part of my shell script to check the total kernel memory usage ...

I want to eliminate the last "Total [segkmem_ppa]" from the list, without hardcoding as grep -v "Total [segkmem_ppa]" as, i dont know what else might include the string kmem at any point.

Any solution ?

try:

grep -v "Total \[segkmem_ppa\]"

try..

echo "::kmastat" | /usr/bin/mdb -k | grep Total | grep "kmem_*"| head -4

Both of the solutions work, but they are hardcoding according to the current output.

Lets say, we dont know how many kmem_*'s are gonna be there in the op, then head -4 wont work..

If segkmem_* is not the only string with kmem included in it, then my result array will include more elements than i need...

??

do you want to just remove the last line? try

echo "::kmastat" | /usr/bin/mdb -k | grep Total | grep "kmem_*" | sed '$d' 

perhaps you want lines which contains '[kmem_' ?

---------- Post updated at 08:20 PM ---------- Previous update was at 08:19 PM ----------

or rather the one which includes 'Total [kmem_' ?

Yes exactly,
I just want lines that include Total [kmem_*]

But if I do a grep kmem, it ends up showing, strings which include kmem, like [segkmem_*....

Rather:

grep "Total \[kmem"

try..

grep 'Total \[kmem.*' file

thanks guys, yeah, i had to escape the opening brace [ ...
thanks for the help

I had it in the first answer xD

thanks chipcmc , yeah i didnt see you had already escaped the [ :wink: