Cut pid from ps using cut command

hay
i am trying to get JUST the PID from the ps command.
my command line is:

ps -ef | grep "mintty" | cut -d' ' -f2
but i get an empty line. i assume that the delimiter is not just one space character, but can't figure out what should i do in order to do that.

i know i can use awk or cut -c1-4 (the pid is in characters 1-4), but i don't want to use them.

is it possible to achieve my goal using cut -f and a combination or -d or -s?

thanks

Tools take leading whitespace characters as one empty field, many empty fields or as leading space of the first field. You might use sed, so you can control field definition with regex. The ps output is also problematic as fields change form by value. Newer ps allow you to specify what fields you want with -o.

thanks, but i want to use only ps, grep and cut, is it eve possible the way i started?

Try using awk instead:

ps -ef | awk '/mintty/&&!/awk/{print $2 } '

OR use pgrep

pgrep mintty

This is a task tailor-made for pgrep. If you insist on using a ps pipeline, why? Is it a homework assignment? Is pgrep not available? If not, what OS are you using?

Regards,
Alister

Doesn't make sense to say "I want to use only ps, grep and cut".

---------- Post updated at 04:23 PM ---------- Previous update was at 04:20 PM ----------

pgrep - I learned something new. Thanks

I had pidof written down in my notebook. That might work for you.

pgrep is almost certainly more reliable than pidof. I am not absolutely certain, but I believe pidof is only found on Linux systems. pgrep (and pkill) are virtually everywhere.

Regards,
Alister

i know it makes no sense to use only ps, grep and cut, but that what my H.W assignment asked for.

i am using windows 8, and run cygwin emulator.
i understood that each terminal has its own display for the ps command, so is there something global that would work for all terminals?

thanks

Read rule #6 @ Simple rules of the UNIX.COM forums:

Regards,
Alister