View Full Version : Need help with a script to extract numbers from a grep stream

March 10th, 2007, 09:18 AM
Hi all,

I need to pass the PID number to a kill command using a simple shell script.

Here's what I need to do in easy steps:

1. Get the PID # of the process, the closest I can get is with:

screen -list | grep Detthis gives the following output:

19729.omnibot (Detached)I'm guessing the leading whitespace is a tab.

2. I need to pass the number to the "kill" command, so the part I need is the actual number extraction engine, so all I get is "19729" which I can then pass on easily.

I've been trying to use grep to filter the numbers, but the best I can do is to use:

screen -list | grep Det | grep -o [0-9]Which works, but it puts a <cr> after each number, ie:

9Any help is greatly appreciated :)

March 10th, 2007, 09:33 AM
screen -list | grep Dep | cut -f1 -d.

With this, after the grep, you will take the first field with dot as a delimiter.

March 10th, 2007, 09:34 AM
you can try these tools