Better use of awk command?

Good morning,

I am trying to figure out how to filter out the ora_pmon part of the results below using a command and so far I have not been able to figure it out.

leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>ps -ef | grep ora_pmon
  tivoli  8105 15855   0 09:28:38 pts/1       0:00 grep ora_pmon
  oracle 20086     1   0   Oct 12 ?          11:15 ora_pmon_entp_stdby
  oracle 24321     1   0   Oct 07 ?          17:20 ora_pmon_ot1p_stdby
  oracle 13929     1   0   Oct 13 ?           9:52 ora_pmon_lawp_stdby
leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>

This seems to be as close as I have been able to get...

leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>ps -ef | grep ora_pmon | grep -v grep | awk '{print $NF}'
ora_pmon_entp_stdby
ora_pmon_ot1p_stdby
ora_pmon_lawp_stdby

The results I am looking for should look like this...

entp_stdby
ot1p_stdby
lawp_stdby

Any ideas on how to dump the ora_pmon_ part?

Thank you in advance.

Try this....

>ps -ef | grep ora_pmon | grep -v grep | awk '{print $NF}' | sed 's/ora_pmon_//g'

ps -ef | grep ora_pmon | grep -v grep | sed "s/.*_pmon_//" 
entp_stdby
ot1p_stdby
lawp_stdby

stay with awk:

ps -e -o comm | nawk -F_ '/^ora_/ {$1=$2="";gsub("^ *", "");print}'
OR
ps -e -o comm | nawk -F'ora_pmon_' 'NF>1 {print $2}'

Another one:

ps -ef | awk '/ora_pmon/{sub(".*ora_pmon_","");print}'

Yep that worked perfectly.

leviathan:/lcl/apps/Tivoli/netcool/omnibus/bin>ps -e -o comm | nawk -F'ora_pmon_' 'NF>1 {print $2}'
entp_stdby
ot1p_stdby
lawp_stdby

If you don't mind could you kinda go through in detail what each part of that is doing? I am really new to it all and want to learn from it.

Thanks.

ps -e -o comm

'man ps' and searching for 'comm' yields:

     comm  The name of the command being executed (argv[0] value)
           as a string.
nawk -F'ora_pmon_' 'NF>1 {print $2}'

Define the Field Separator (FS) as a string 'ora_pmon_' - that how ALL your searched for entries start with.
If the the output of 'ps -e -o comm' has more than ONE field (records containing 'ora_pmon_' as a separator) - it means it's a 'searched for' record/line -> then output the SECOND field - the field FOLLOWING the FIRST 'ora_pmon_' separator.

HTH
NOTE: Netcool, eh? Nice - welcome to the wonderful work of Fault Management.

Thanks! :slight_smile: