Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Editing a text file with sed

From: Joe Hart <j.hart(at)orange.nl>
Date: Fri Aug 31 2007 - 16:29:55 EDT


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

-- 
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Received on Fri Aug 31 16:30:04 2007

This archive was generated by hypermail 2.1.8 : Sun Oct 07 2007 - 03:27:25 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library