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

Re: Editing a text file with sed



On Wednesday 29 August 2007 15:48:50 Victor Munoz wrote:
> On Wed, Aug 29, 2007 at 03:17:46PM +0200, 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:
> >
> > sed s/\n// / 1.txt > 2.txt and I get an error, so:
> > sed s'\n/ /' 1.txt > 2.txt and nothing happens.
> >
> > I don't get it.  I though \n was end of line, which I am trying to
> > replace with spaces.
>
> sed works line by line, separately. There's an N modifier to make it
> work across lines. You may check
> http://www.panix.com/~elflord/unix/sed.html for a nice tutorial, or
> http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html for some examples.
>

Thanks victor, upon further testing, perhaps sed isn't what I should be using 
in the first place.  tr seems to be a better candidate, yet I cannot get this 
working either.  

It seems like such a simple thing to do, perhaps I need to write a program 
that will do it, but I thought surely there'd be a simple (or maybe not so 
simple) command line that would just do it.  I don't care if it's sed, or tr, 
awk, perl, python, whatever... as long as I get the stupid hard returns out.

Joe



Reply to: