A very quick way is using awk
awk 'BEGIN{RS="";ORS="\n\n"}1' /path/to/your/file > /path/to/new/file
How does this work:
awk knowns the concept records (which is by default lines) and you can define a record by its record separator RS
. If you set the value of RS
to an empty string, it will match any multitude of empty lines as a record separator. The value ORS
is the output record separator. It states which separator should be printed between two consecutive records. This is set to two <newline> characters. Finally, the statement 1
is a shorthand for {print $0}
which prints the current record followed by the output record-separator ORS
.
1
solved How to match two new lines (\n) instead of one, in regex? [duplicate]