Operating System - HP-UX
1838005 Members
5422 Online
110124 Solutions
New Discussion

I am tring to isolate a part of a line.

 
SOLVED
Go to solution
Juan Gonzalez_2
Frequent Advisor

I am tring to isolate a part of a line.

I am doing sar -v 5 | awk '{print $4}'|grep 4200 |awk '{ cnt = split( $2, parts, "/" ); {print $1}}' but this still gives me for example 425/4200 output. What I want to isolate is the 425 but this number could be two digits or three digits or four digits long so I can not use the cut command at least I do not thing so. I want to get the amount of processes that are running on the server so I can compare that to maybe 4000 then sent out an alert. Can any body help?
thanks in advance.
7 REPLIES 7
Patrick Wallek
Honored Contributor
Solution

Re: I am tring to isolate a part of a line.

Try this:

# sar -v 5 | grep 4200 | awk '{print $4}' | awk -F \/ '{print $1}'

IT_2007
Honored Contributor

Re: I am tring to isolate a part of a line.

use option -F "\/" to ignore slash.
IT_2007
Honored Contributor

Re: I am tring to isolate a part of a line.

use option -F "\/" in awk to ignore slash.
spex
Honored Contributor

Re: I am tring to isolate a part of a line.

Hi Juan,

You could replace that drawn-out command with:

# ps -e | wc -l

PCS
James R. Ferguson
Acclaimed Contributor

Re: I am tring to isolate a part of a line.

Hi Juan:

How about:

# sar -v 5 | awk 'NR>4 {cnt=split($4,parts,"/");print parts[1]}'

Regards!

...JRF...
Juan Gonzalez_2
Frequent Advisor

Re: I am tring to isolate a part of a line.

Thanks everyone for the good information.
Sandman!
Honored Contributor

Re: I am tring to isolate a part of a line.

# sar -v 5 | awk '{if (int(z[split($4,z,"/")]) > 4000) print z[1]}'