Question: I have a document:

```
column1: 23
column2: 42
kolumn3: 24
column1: 24
column2: 35
kolumn3: 46
column1: 25
column2: 42
column1: 35
column2: 45
kolumn3: 52

```

And I'd like my output to be:

```
column1: 23
column2: 42
kolumn3: 24
column1: 24
column2: 35
kolumn3: 46
column1: 35
column2: 45
kolumn3: 52

```

The output must be in `column1`, `column2`, `kolumn3` order. Remove everything that is not in this order.

Is it possible to do this in `grep`, `sed` or `awk`?

Answer: 
Using GNU awk:

```
awk -v RS='column1: [0-9]+\ncolumn2: [0-9]+\nkolumn3: [0-9]+\n' '{printf RT}' file

```

The record separator `RS` is a regex set to catch the 3 consecutive lines. 

The only statement is to print the record terminator `RT` leaving out everything that is not caught by `RS`.
This will do the trick in awk, let's call it testcol.awk:

```
$1=="column1:" {l1=$0; n=2;}
$1=="column2:" && n==2 {l2=$0; n=3;}
$1=="kolumn3:" && n==3 {print l1 "\n" l2 "\n" $0; n=1}

```

Then run something like

```
awk -f testcol.awk your_input_file

```