From: "KEVIN ZEMBOWER" <[EMAIL PROTECTED]> > 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, whether or not they're separated by whitespace characters.
As a script: #!perl -w $/ = ''; # see perldoc perlvar while (<>) { s/ *\n */ /g; # convert newlines to spaces s/^ +//; # strip leading spaces s/ +$//; # strip trailing spaces print $_, "\n"; } As an oneliner: perl -ni.bak -e "BEGIN{$/=''}; s/ *\n */ /g; s/^ +//; s/ +$//;print $_, qq{\n}" filename.txt HTH, Jenda =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]