in reply to Re^2: Removing double carriage return
in thread Removing double carriage return
perl -i.bak -0777 -pe 's/(\n{3,}|\n\n)/2 == length $1 ? "\n" : "\n\n"/eg' inputfile
Notice that this looks for the longest match first (so that 2 newlines won't match more than 2, i.e. 3 or more).
Update: That could be simplified to:
perl -i.bak -0777 -pe 's/\n+/2 < length $& ? "\n\n" : "\n"/ge' inputfile
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Removing double carriage return
by dragooneye (Novice) on Aug 26, 2011 at 17:29 UTC |