1834909 Members
2717 Online
110071 Solutions
New Discussion

Re: Help with awk

 
wvsa
Regular Advisor

Help with awk

Greetings all;

I'm trying to remove the % sign from the following awk command:

memchk | grep physical | awk '{print $5}'

The value printed is 75% need to find a way to remove the % sign.

Thank you for your input.

Norm
6 REPLIES 6
Hasan  Atasoy
Honored Contributor

Re: Help with awk

Hi

memchk | grep physical | awk '{print $5}' | tr -d "%"

Hasan
Sandman!
Honored Contributor

Re: Help with awk

# memchk | awk '/physical/ {print z[split($5,z,"%")-1]}'
Padma Asrani
Honored Contributor

Re: Help with awk

hi

This should also work

memchk | grep physical |awk '{print $5}' | awk -F '%" '{print $1}'

Regards
Padma
James R. Ferguson
Acclaimed Contributor

Re: Help with awk

Hi Norm:

You could also do:

# memchk|awk '/physical/ {sub(/%/,"",$5);print}'

This eliminates the extra process (viz. 'grep') along with accomodating your request!

Regards!

...JRF...
wvsa
Regular Advisor

Re: Help with awk

Thanks to all who responded. All the solutions worked. It was a good awk learning experience.

Norm
Dennis Handly
Acclaimed Contributor

Re: Help with awk

If you are happy with the answers you have gotten please read the following. You should reopen the thread and assign points:
http://forums12.itrc.hp.com/service/forums/helptips.do?#41
http://forums12.itrc.hp.com/service/forums/helptips.do?#33
Questions or topics with unassigned points
http://forums11.itrc.hp.com/service/forums/pageList.do?userId=CA38694&listType=unassigned&forumId=1