[plug] Small problem with cut

J Michael Gilks mike at gilks1.com
Sun May 16 03:48:08 WST 2004


Rather than just sending out a reply, I have now tested using cut and 
discovered th problem.
The output going to cut is not tab delimited but uses spaces.
On your system
ps aux | grep "kdeinit: konqueror -session" | cut -f 6 -d " "
should give the result you are after. Still very dependent on size of names 
etc.
Got it. Need to convert space to tabs, use perl
ps aux|grep "kdeinit: konqueror -session"|perl -p -e 's/\s+/\t/g' - | cut -f2
Little perl bit converts one or more spaces to a tab, therefore fields are 
where they should be. This has been fun, hope it has helped.

Love
Mike.

On Sun, 16 May 2004 02:14 am, Sawan Vithlani wrote:
> Hello All.
>
> I have a small problem with using the cut utility:
>
> I want to grab the pid of a certain process, so try this:
>
> ps ux|grep "kdeinit: konqueror -session"
>
> This gives me the whole process line, the second field of which is the pid
> as shown:
>
> sawan     6460  0.3 11.8 77976 61448 ?       S    May14   7:08 kdeinit:
> konqueror -session 113ffb8855000108305114500000066510347_1084124886_479563
>
> What option to I have to give to cut if I want to pipe the above to extract
> the second field of the line?
>
> cut -b 11-16 seems to work but that will depend on the pid; a longer pid
> breaks it.
>
> I know about pidof; cant seem to get it to match the process "kdeinit:
> konqueror -session". Same problem with pgrep.
>
> Any help? even using some other utility.....
>
> Thanks
>
>
> _______________________________________________
> PLUG discussion list: plug at plug.linux.org.au
> http://mail.plug.linux.org.au/cgi-bin/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au



More information about the plug mailing list