Filter on a grep

I am attempting to figure out how to only capture part of a grep command I am doing. So far no luck.

When I execute....

leviathan:/gfs/home/tivoli>ps -ef | /usr/ucb/ps -auxww | grep nco_p_syslog

The results are....

tivoli   10185  0.0  0.0 5888 5168 ?        S   Oct 23  0:26 /lcl/apps/Tivoli/netcool/omnibus/probes/solaris2/nco_p_syslog -manager lawp_stdby.syslog -propsfile /lcl/apps/Tivoli/netcool/omnibus/probes/solaris2/syslog.lawp_stdby.props

I want to only have the output list lawp. So another words how can I capture anything between the . and the _ which would result in lawp.

Thank you

Rather than try to filter out the "lawp" part of the output why not include it in the grep pattern "nco_p_syslog.*lawp.*" If the grep returns true then you could output "lawp" as a string if you need it.

You can try something like this to filter the result:

sed 's/.*\.\(.*\)_.*/\1/'

Even this before the grep command:

sed -n '/nco_p_syslog/ s/.*\.\(.*\)_.*/\1/p'