Question: I have a data gethered in one file organised in blocks

```
---- BLOCK ONE ----
some data
another data
more data
more data
-------------------

---- BLOCK two ----
some data
another data
-------------------

---- BLOCK THREE ----
some data
another data
more data
-------------------

```

and so one. togethere around 2000 blocks.

I need to extract those blocks which have less then 4 entries (data lines).
Any idea how to do it (perl prefered ; )

Answer: 
Here's a simple one liner:

```
$ perl -00 -lne '@k=(/\n/mg); print if $#k < 4 ' file
---- BLOCK two ----
some data
another data
-------------------

---- BLOCK THREE ----
some data
another data
more data
-------------------

```

The `-00` turns on "paragraph mode" which treats each block of lines separated by an empty line as a single "line". The `-l` adds a newline character to each `print` call and strips trailing newlines from each input "line", and the `-n` means "run the script given by `-e` on each line of the input".

The script itself looks for `\n` characters in the input "line" (paragraph) and stores them in an array. Then, if the largest index of the array is less than 4, we print the line. Remember that arrays start counting at `0`, so this means that if we have less than 4, since the first line is also counted, but the last one is not because its trailing newline has been removed by `-l`, then we have fewer than 4 lines inside the block.
Using any `awk`:

```
awk 'NF && !/^-/{ buf= buf (data?ORS:"") $0; data++ }
          /^-+$/{ if(data<4) { print (ors?ORS:"") buf; ors=ORS }; buf=data="" }' infile

```

Output:

```none
some data
another data

some data
another data
more data

```

If you wanted to keep the blocks header/footer:

```
awk 'NF{ buf= buf (data?ORS:"") $0; data++ }
 /^-+$/{ if(data<=5) { print (ors?ORS:"") buf; ors=ORS }; buf=data="" }' infile

```

Output:

```none
---- BLOCK two ----
some data
another data
-------------------

---- BLOCK THREE ----
some data
another data
more data
-------------------

```