Question: I would like to match the pattern,789. using only one sed command.(no multiple commands linked with "-e")

The rule is to match the number after the third fax.

```
echo "fax 123 def fax tel 456 fax 789 fax 976" | sed 's/xxxxxxx/'

```

Answer: 
Using `awk` with `fax` as the delimiter:

```
$ echo "fax 123 def fax tel 456 fax 789 fax ghi" | awk -F'fax ' '{print $4}'
789

```

With `sed`:

```
$ echo "fax 123 def fax tel 456 fax 789 fax ghi" | sed 's/.*fax \([0-9]\+\).*/\1/'
789

```

**Edit:** `sed` is line based so how about using `grep` to first split the fields:

```
$ echo "fax 123 def fax tel 456 fax 789 fax 976" | egrep -o 'fax (tel )?[0-9]+'
fax 123
fax tel 456
fax 789
fax 976

```

Then use `sed` to specify which line *(field)*:

```
 $ ... | sed -n '1s/^[^0-9]*//p'
 123

 $ ... | sed -n '2s/^[^0-9]*//p'
 456

 $ ... | sed -n '3s/^[^0-9]*//p'
 789

```
I finally used a command like:

```
echo "  fax 123 def fax tel 456 fax 789 fax 012" |  
sed -e 's/^\s*fax\s*[0-9a-z]*\s*[a-z0-9]*\s*fax\s*[0-9a-z]*\s*[0-9a-z]*\s*fax\s*\([0-9]*\).*$/\1/'

```