Question: I have a list like this:

```
5678:robert dylan   :d.g.m. :marketing  :04/19/43 85000

```

I want to show only the name and designation of the person. I want to use `sed` for that. How should I do that?

Answer: 
This might work for you:

```
echo "5678:robert dylan :d.g.m. :marketing :04/19/43 85000" |
sed 's/[^:]*:\([^:]*:\)[^:]*:\([^:]*\):.*/\1\2/'
robert dylan :marketing

```

Explanation:

The left hand side (LHS) of the substitute command says:

* `[^:]*:` match zero or more non `:`'s followed by a `:` - this matches `5678:`
* `\([^:]*:\)` as above but will be remembered as a back reference `\1` - matches `robert dylan :`
* `[^:]*:` as above but no back reference - matches `d.g.m. :`
* `\([^:]*\)` as above (excepting the `:` but will be remembered as a back reference `\2` - matches `marketing`
* `:.*` a `:` followed by everything else - matches `:04/19/43 85000`

The right hand side of the substitute command says:

* `\1\2` replace the left hand side by the first and second back references.
Similar to [Lavon's approach](https://stackoverflow.com/a/11376656/438457), but adapted to multiple records

```
sed -n 's/:/\n/pg' file | sed -n '2~5h;4~5{H;g;s/\n/|/g;p}'

```

will produce 

```
robert dylan |marketing 
penny farthing |accident & emergency 
...

```

For input file 

```
5678:robert dylan :d.g.m. :marketing :04/19/43 85000
8076:penny farthing :d.g.m. :accident & emergency :04/19/43 85000
...

```

First replace `:` with `\n` new-line to get 5 lines per record; then 
for each set of 5 lines, copy the 2nd and append the 4th to the holding space, transfer to the pattern space, replace `\n` with a separator (in this case `|`) and print. (If you don't care about column order `{H;g;...` can be shortened to `{G;...`.)