A bash problem

Hi,

I'm fairly new to unix, and I have the following problem:

I know that if I type, "ps -ef | grep process", this will return some information about the process named 'process'. What I need this to do is be piped to an extra search that pick's out process' PID. How do I do this?

Thanks in advance for your help!

try this..

pgrep "process"   #it will give you PID for process.
1 Like

awk can do that all in one operation. Match lines containing 'process', print the second column.

The [p] is to prevent awk from matching itself. It will match 'process', not '[p]rocess', and thus avoid printing the PID for its own process.

ps -ef | awk '/[p]rocess/ { print $2 }'
1 Like

There's a command that does exactly what I want. Huh! Thanks for that!

And, of course, there is

pidof process

awk is an entire programming language and can do a lot more than just that.