How to grep more than 2 fields?

Hi all,

Currently I have this:
ps -eo pid,comm| grep CSORDB1T

But I need to grep LOCAL=NO as well:
ps -eo pid,comm| grep CSORDB1T |grep LOCAL=NO >pdwh_pid

However, there's no output. Plz advise how can we grep CSORDB1T & LOCAL=NO at the same time.

Thanks!

use awk
if you want to display when both found use this..

ps -eo pid,comm|awk '/CSORDB1T/&&/LOCAL=NO/{print}'

otherwise

ps -eo pid,comm|awk '/CSORDB1T/||/LOCAL=NO/{print}'

Thanks for the reply.

Both of them did not work for me.

I would wan to have the below:
bash-3.00$ ps -ef |grep CSORDB1T |grep LOCAL=NO
oracle 22322 1 0 14:51:21 ? 0:39 oracleCSORDB1T (LOCAL=NO)
oracle 8839 1 0 22:05:28 ? 1:53 oracleCSORDB1T (LOCAL=NO)
oracle 8066 1 0 10:52:56 ? 0:00 oracleCSORDB1T (LOCAL=NO)

How to get the similiar output by using ps -eo?
Thank you.

you are using wrong option with -o
for the desired output use

ps -eo 'pid,args'|awk '/CSORDB1T/&&/LOCAL=NO/{print}'

Thanks.

For the output:
bash-3.00$ ps -eo 'pid,args'|awk '/CSORDB1T/&&/LOCAL=NO/{print}'
22322 oracleCSORDB1T (LOCAL=NO)
19855 oracleCSORDB1T (LOCAL=NO)
8839 oracleCSORDB1T (LOCAL=NO)
8066 oracleCSORDB1T (LOCAL=NO)
19915 awk /CSORDB1T/&&/LOCAL=NO/{print}

The last pid which is this current session, how could we eliminate this? Which is only to output the pid of other user session not including my current session?

Thank you.

simple...:slight_smile:
use

ps -eo 'pid,args'|awk '/CSORDB1T/&&/LOCAL=NO/&&!/awk/{print}'

Simplify...

$ ps -eo 'pid,args' | egrep 'CSORDB1T.*[(]LOCAL=NO[)]'

again it wil show egrep process in ps -eo i guess

Nope, watch the magic:

$ cat in

22322 oracleCSORDB1T (LOCAL=NO)
19855 oracleCSORDB1T (LOCAL=NO)
8839 oracleCSORDB1T (LOCAL=NO)
8066 oracleCSORDB1T (LOCAL=NO)
9099 ps -eo 'pid,args' | egrep 'CSORDB1T.*LOCAL=NO'

$ cat in | egrep 'CSORDB1T.*[(]LOCAL=NO[)]'
22322 oracleCSORDB1T (LOCAL=NO)
19855 oracleCSORDB1T (LOCAL=NO)
8839 oracleCSORDB1T (LOCAL=NO)
8066 oracleCSORDB1T (LOCAL=NO)