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`.
Another (a brain bug that wouldn't leave me alone before I typed it in, pretty untested though):

```
$ awk '
BEGIN {
    p="column1:column2:kolumn3:"  # comparison pat- NO, something else ;D
}
p~"^" b $1 {                      # if gathered $1 buffer matches the p
    b=b $1                        # keep collecting
    c=c $0 ORS
    if(p==b) {                    # prefect match deserves to be outputed
        printf c
        b=c=""                    # reset buffer vars
    }
    next                          
}
{                                 # a non-match means a reset and restart 
    b=$1                          # for buffer vars
    c=$0 ORS
}' file

```

Output:

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

```