Re: Editing a text file with sed
This command erases all line breaks
sed -e :a -e '$!N;s/\n/ /;ta' -e 'P;D'
although you have to adapt it to not delete paragraphs. Using regex, the
line would then become something like
sed -e :a -e '$!N;s/\n[^\n]/ /;ta' -e 'P;D'
Good luck.
Sjoerd
Joe Hart schreef:
> 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.
>
> I understand that this would loose the paragraphs, so ideally what I need to
> do is something like this:
>
> 1. Replace double line breaks with special sequence not found in text.
> 2. Convert all line breaks to spaces
> 3. Convert special seqeuence to double line breaks.
>
> I thought sed would be perfect for this, but no such luck. I can get what I
> want by using kwrite for step 1 and 2, then OO.o Writer for step 3. (kwrite
> seems unable to do step 3)
>
> 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.
>
> Joe
>
>
Reply to: