wegelin has asked for the wisdom of the Perl Monks concerning the following question:
I work at the unix command line (bash shell) on a Mac 10.6.8. In a text file, I want to replace all multiple newlines, even if the newlines have other whitespace between them, with EEEEE. All single newlines I want to leave alone. Thus the following file, called textfile:
dogs rats cats fishmust be transformed into
dogs rats catsEEEEEfishBut as you see from the example below, the following regular expression, issued at the command line, doesn't do it.
Here is the example:s/\n\s*\n/EEEEE/g
> cat textfile dogs rats cats fish > perl -p -e 's/\n\s*\n/EEEEE/g' textfile dogs rats cats fish
Is there a simple or elegant solution?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regular expression: match multiple newlines
by Cristoforo (Curate) on Nov 03, 2013 at 19:42 UTC | |
by Kenosis (Priest) on Nov 03, 2013 at 19:55 UTC | |
by Cristoforo (Curate) on Nov 03, 2013 at 20:13 UTC | |
by Kenosis (Priest) on Nov 03, 2013 at 20:47 UTC | |
Re: regular expression: match multiple newlines
by Lennotoecom (Pilgrim) on Nov 04, 2013 at 01:22 UTC | |
Re: regular expression: match multiple newlines
by Kenosis (Priest) on Nov 03, 2013 at 19:38 UTC |
Back to
Seekers of Perl Wisdom