Re: Newbie: Replacing double newlines
- From: Ben Bullock <benkasminbullock@xxxxxxxxx>
- Date: Sat, 9 Aug 2008 01:26:47 +0200 (CEST)
On Fri, 08 Aug 2008 18:37:27 -0400, Jensen wrote:
Hello:
This works for me to replace single newline characters with spaces:
perl -pe 's/\n/ /g' test2
in a file.
However, when I want to replace just the double newlines (two of them in
sequence), with:
perl -pe 's/\n\n/ /g' test2
it doesn't work.
This reads it line by line, so since there isn't a single line with two \n
on it, it doesn't work.
The best solution I could think of for your problem was something like this:
perl -pe's/\n/\\n/g' test.txt|perl -pe 's/(\\n){2,}/\\n/g' | perl -pe 's/\\n/\n/g'
Here I'm assuming that you didn't really want to turn \n\n into a space.
But someone else can probably do it better than that.
.
- References:
- Newbie: Replacing double newlines
- From: Jensen
- Newbie: Replacing double newlines
- Prev by Date: Re: Newbie: Replacing double newlines
- Next by Date: Re: Newbie: Replacing double newlines
- Previous by thread: Re: Newbie: Replacing double newlines
- Next by thread: Re: Newbie: Replacing double newlines
- Index(es):