Linux Newbie help
 help / color / mirror / Atom feed
From: John Kelly (bilbo) <bilbo@waitrose.com>
To: linux <linux-newbie@vger.kernel.org>
Subject: Re: Extraction of PID
Date: Sat, 26 Jul 2003 09:11:54 +0100	[thread overview]
Message-ID: <20030726080844.SXTP2652.mta03-svc.ntlworld.com@there> (raw)
In-Reply-To: <20030726065829.DD46B1041E@heisspf>

On Saturday 26 July 2003 7:58 am, Peter wrote:

>Hi,
>
>How do I isolate from a line like
>
>1865 tty2 00:00:18 exmh
>
>the first 4 numbers which is the PID. I get it with "ps -a --pid 1111 | grep 
>exmh".
Hi,
As usual in 'nix there are several different ways of doing this.
My first guess was:

ps -a -pid 1111 | grep exmh | awk '{print $1}'

Which works fine for me on my Redhat box.

Second guess was:

ps -a -pid 1111 | awk '/exmh/{print $1}' 

Which also worked fine.

Since not many people use awk, I though I would try a few examples with the 
cut command.

ps -a -pid 1111 | grep exmh | cut -d' ' -f1

This example works but I had to use the -d option to specify the delimiter.
If you were sure the pid was only going to be four characters long, you could 
use:

ps -a -pid 1111 | grep exmh | cut -c1-4

I have just spent the past ten minutes messing about using sed to do this too 
- but I don't think any sane person would used sed to do something like this. 
But for what it is worth, here is my sed example

ps -a -pid 1111 | sed -ne '/exmh/s/ tty.*$//'


Your best bet is probably to use the 
ps -a -pid 1111 | grep exmh | cut -d' ' -f1
example. But rememeber that there is hours to fun to be had messing about 
with obscure programs on nix systems. :-)

regards

John Kelly
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

  reply	other threads:[~2003-07-26  8:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-26  6:58 Extraction of PID Peter
2003-07-26  8:11 ` John Kelly [this message]
2003-07-26  8:22 ` pa3gcu
2003-07-27  5:36   ` Peter
2003-07-26 10:57 ` chuck gelm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030726080844.SXTP2652.mta03-svc.ntlworld.com@there \
    --to=bilbo@waitrose.com \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox