How to replace multiple blank lines with a specific non-blank line

awksed

The sample input is

1
2
3


4
5



6
7
8



9

The expected output is

1
2
3
---
4
5
---
6
7
8
---
9

Best Answer

One way:

cat -s file | sed 's/^$/---/'

From man page of cat :

   -s, --squeeze-blank
          never more than one single blank line

Once cat has squeezed the blank lines, sed replaces the blank with with a ---

Related Question