in reply to Re^2: Adding back missing newlines between records
in thread Adding back missing newlines between records

The -p flag creates a while(<>) loop around the code specified for the -e flag(with print; as the last line in the while loop)

Actually, that's not quite accurate. According to what I read, the while loop looks like this:

LINE: while (<>) { # your code goes here } continue { print or die "-p destination: $!\n"; }

A continue block gets executed the instant before the loop condition is evaluated. So 'redo' does not cause the continue block to execute, but 'next' does, and a normal iteration of the loop causes the continue block to execute as well.

This works for me:

perl -pe 'if($_ eq "\n"){$n=1;next;} if($n){$n=0;next;}else{s/# file/\ +n# file/;}' data1.txt