in reply to Re: newlines in regular expressions
in thread newlines in regular expressions
perl -p -e 'BEGIN { undef $/ } s/\n{2,}/\n/g'
Also, the two examples behave differently in the face of lines that contain only blank characters, like space and tab. The second will delete them, while the first will leave them intact. You can make the second leave them intact by using m/^$/; to make the first delete whitespace-only lines I think s/\n\s*\n/\n/g will work, but I haven't thought it through yet.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: newlines in regular expressions
by eyepopslikeamosquito (Archbishop) on Dec 07, 2004 at 07:22 UTC | |
|
Re^3: newlines in regular expressions
by tachyon (Chancellor) on Dec 07, 2004 at 12:09 UTC | |
|
Re^3: newlines in regular expressions
by tachyon (Chancellor) on Dec 07, 2004 at 11:59 UTC |