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

Re: Editing a text file with sed



On Wed, Aug 29, 2007 at 15:17:46 +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>

[...]

> But ideally I'd like to just have a script to do it, but cannot figure out how 
> to go about it, as sed doesn't seem to be working.

Why not use Perl?

$ perl -p0e '$_=~s/(.)\n(.)/$1 $2/g' < 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.

$ perl -p0e '$_=~s/(.)\n(.|\n)/$1 $2/g;$_=~s/ \n/\n/g' < 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.

-- 
Regards,            | http://users.icfo.es/Florian.Kulzer
          Florian   |



Reply to: