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?
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.
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?
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.
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?