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 might work for you (GNU sed):

```
sed ':a;N;/^column1:.*\ncolumn2:/!D;N;/\nkolumn3:/b;s/.*\n//;ta' file

```

Read two lines into the pattern space and if they do not match `column1:` followed by `column2:` delete the first and repeat. Otherwise, append a third line and if this matches `kolumn3:` print all three lines, if not, remove the first two lines and jump back to the beginning of the sed script.

Another solution:

```
sed -n '/\n/!N;N;/^column1:[^\n]*\ncolumn2:[^\n]*\nkolumn3:[^\n]*$/p;//!D' file

```