From: Mister B on
Can you advise me of ways to select the last field of piped text (I
actually want to extract the last parameter of a "ps" output).
I presume this can be done with cut, sed, awk etc, but wonder which is
easier + any drawbacks

Thanks
M
From: pk on
Mister B wrote:

> Can you advise me of ways to select the last field of piped text (I
> actually want to extract the last parameter of a "ps" output).
> I presume this can be done with cut, sed, awk etc, but wonder which is
> easier + any drawbacks

If depends on how you define "field". If that's just space/tab separated,
just

.... | awk '{print $NF}'

will work.

From: johnb850 on
On Jan 8, 3:38 am, pk <p...(a)pk.invalid> wrote:
> Mister B wrote:
> > Can you advise me of ways to select the last field of piped text (I
> > actually want to extract the last parameter of a "ps" output).
> > I presume this can be done with cut, sed, awk etc, but wonder which is
> > easier + any drawbacks
>
> If depends on how you define "field". If that's just space/tab separated,
> just
>
> ... | awk '{print $NF}'
>
> will work.

Some ideas;
Given ps does do fixed width formatting
$ ps
PID TTY TIME CMD
3282 pts/0 00:00:05 bash
13599 pts/0 00:00:00 ps

Then we can use the char option of cut, to take from 25th char to the
right,
$ ps |cut -c 25-
CMD
bash
ps
cut

OR, make use of the cool formatting options ( linux ) in ps to single
out the one field, see man ps.
ps -o comm
COMMAND
bash
ps

have fun.