[Solved] How can I pull specific information from PS?

I need to grab information from the output of the ps command.

For each line of ps output that contains

_progres -b

I need to get the word that follows

-p

. The "-p" can be anywhere after

"_progres -b"

.

Using grep to select the correct lines is no problem (e.g.

ps -ef|grep "_progres \-b|grep -v grep

). Or

ps -ef | awk ' /_progres \-b/ {print $0}'

. Although there maybe better ways.

It's what comes after that where I need some suggestions.

TIA :slight_smile:

Can you paste the output of the ps command?

May be something like this?

ps -eaf | awk '/_progres -b/{ gsub(/.*_progres -b.*-p/, x); print $1}' 

--ahamed

Try this:

 ps -ef | awk '/_[p]rogres /&&/-b/&&/-p / { gsub(/.* -p /, ""); print $1}'

Note with progress batch sessions, the -b can also appear anywhere on the line (even at the end):

chubler    17030 17024  0 02:02 ?        00:00:02 /usr/dlc/102b/bin/_progres -pf /u/learn/b2b.pf -p my-proc.p -param EFT=y -param TIMEOUT=1800 -b

Thanks to both of you for the replies.

Chubler, thanks for the reminder the -b can appear anywhere as well.

Solved!