Steve Grazzini wrote: > > Kevin Zembower <[EMAIL PROTECTED]> wrote: > > I'm facing what I believe to one of the classic text manipulation > > problems, transforming a document which was typed with a hard return > > at the end of every physical line, and two consecutive newlines to > > mark the end of a paragraph. > > > > Would anyone help me write a program which would transform these > > documents? I'm trying to find all instances of a single newline, > > and remove it, either inserting or removing space characters around > > where it was to leave just one space between what was the two lines. > > I also need to substitute a single newline for two or more consecutive > > newlines, > > $ perl -pi~ -00 -le 'BEGIN{ $\="\n" } s/\s*\n\s*/ /g' file.txt
perl -pi~ -00 -l012e's/\s*\n\s*/ /g' file.txt > > whether or not they're separated by whitespace characters. > > Well. That's a bit trickier, since you can't use paragraph-mode. > > #!/usr/bin/perl -pi~ -0777 > # [untested:] > > s{ /s*? /n (\s*) } ^^ ^^ s{ \s*? \n (\s*) } > { $1 =~ tr/\n // ? "\n" : " " }xeg John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]