perl or awk remove empty lines when condition

Hi Everyone,

[root@]# cat 1
a
b b
cc


1
2
3 3 3

4
55 5


a

b
[root@]# awk -vRS="" '{gsub("\n","")}1' 1
ab bcc
123 3 3
455 5
a
b

but the output should be:

ab bcc
123 3 3455 5
ab

means only when two empty lines only consider new record, otherwise if just has one empty lines in between, conbime lines.

Please advice.
Thanks

Try this,

awk -vRS="\n\n\n+" '{gsub("\n","")}1' infile
1 Like

:b::b::b: