[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Editing a text file with sed



On Wednesday 29 August 2007 17:26:25 Mumia W.. wrote:
> On 08/29/2007 08:17 AM, Joe Hart wrote:
> > I am having trouble using sed to edit text files, heres a good example of
> > what I am looking for:
> >
> > <begin 1.txt>
> > This is a test
> > file, what I am
> > trying to do is get the lines to join.
> >
> > It isn't a complicated thing,
> > but I also want to keep the paragraphs
> > separate.
> > </end 1.txt>
> >
> > I try this command:
> > [...]
>
> Here's another Perl solution:
>
> perl -00 -pe 's/\n+(?!$)/ /g; s/\n\n$/\n/' myfile.txt
>
> If you want to keep the blank lines between paragraphs, remove the
> second substitution.

Thank you everyone, that little bit of perl seems to work, and yes I did want 
to keep the blank line so I end up with:

perl -00 -pe 's/\n+(?!$)/ /g;' < 1.txt > 2.txt

which is exactly what is written above - the second substitution.  I did use 
the dos2unix command first which may have helped.

In any event, my problem is solved and I am a happy camper.  I knew it could 
be done, and in the process I have learned quite a bit about regex and even 
can get a clue what that perl is doing, although I am still not quite capable 
of creating such a masterpiece of a line.

Joe









Reply to: