Question: My text file has a few lines like this...

```
some data here Waiting on job_bba6b2a1589b4535a804e7877dc1fe11 ... (409s) Current status: DONE 
some data there Waiting on job_xyz ... (240s) Current status: DONE 

```

I need to find the job id. In the example mentioned above...

```
bba6b2a1589b4535a804e7877dc1fe11
xyz

```

I can use grep, but how to select only the ID?

cat file.log | grep 'Waiting on job\_'

Answer: 
if this is what you need?

```
kent$  echo "some data here Waiting on job_bba6b2a1589b4535a804e7877dc1fe11 ... (409s)"|grep -oP "(?<=Waiting on job_)[^ ]*" 
bba6b2a1589b4535a804e7877dc1fe11

```
```
sed 's/.*Waiting on job_\([^ ]*\).*/\1/'

```

For each line containing `Waiting on job_` followed by 0 or more non-space characters, this will substitute the whole line (because starting and ending `.*` are going to greedily take as many characters as possible) using back-reference `\1` to recall everything that was matched between `\(` and `\)`, i.e. the non space characters `[^ ]*` you are looking for.

So:

```
cat file.log | grep 'Waiting on job_' | sed 's/.*Waiting on job_\([^ ]*\).*/\1/'

```

or simpler:

```
grep 'Waiting on job_' file.log | sed 's/.*Waiting on job_\([^ ]*\).*/\1/'

```