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: 
**Update**:

```
echo "5678:robert dylan :d.g.m. :marketing :04/19/43 85000" | 
sed 's/:/\n/g' | sed '1d;3d;$d'| sed 'N;s/\n/ - /'

```

yields

```
robert dylan - marketing

```

*Explanation:*

Works by splitting the line into several lines based on `:`, deleting the first, third and last lines, and then joining them up again. 

**NOTE**: In the last expression, *you can specify what separates the name from the designation* by putting something else between the final set of `/ /` in `'N;s/\n/ /'`

---

*Previous AWK solution*:

Not `sed`, but `awk` is quite a natural tool for this if it is acceptable:

```
$ echo "5678:robert dylan :d.g.m. :marketing :04/19/43 85000" | awk -F":" '{print $2, $4}'

```

yields

```
robert dylan  marketing

```

Alternatively, if your data was stored in a file named `data.txt`:

```
awk -F":" '{print $2, $4}' data.txt

```

would produce the same output.

[awk](http://www.grymoire.com/Unix/Awk.html) is really well suited for these sort of tasks.

*Explanation*:

```
awk -F":" '{print $2, $4}'

```

`-F` sets the field separator to `:`, `print $2, $4` print resulting fields 2 and 4 respectively. You can use `printf` to format the output as specific as you need.
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;...`.)