On Thu, Jul 23, 2009 at 8:12 AM, George George<george.githinji / gmail.com> wrote:
> Thanks you for the replies. Both approaches did not seem to achieve what
> i envisaged. Is because of reading the input as a string? rather than as
> a file?
>
> Maybe to rephrase what i really wanted was to be able to delete the
> repeated lines and only remain with a single empty line.
> meaning if a file had the lines;
>
> tetetetetetetete
> tetetettetetetete
>
>
>
> rererererererere
> rerererererererr
>
> remove the empty lines leaving only a single one
>
> tetetetetetetete
> tetetettetetetete
>
> rererererererere
> rerererererererr

Do you have a more specific test case (with code) that is failing?
Reading from a file and using Glenn Jackman's gsub, seems to produce
your desired output:

> cat z
tetetetetetetete
tetetettetetetete



rererererererere
rerererererererr
> ruby -ve 'puts File.new("z").read.gsub(/((?:\r?\n){2})(?:\r?\n)*/, "\\1")'
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux]
tetetetetetetete
tetetettetetetete

rererererererere
rerererererererr
> unix2dos z
unix2dos: converting file z to DOS format ...
> ruby -ve 'puts File.new("z").read.gsub(/((?:\r?\n){2})(?:\r?\n)*/, "\\1")'
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux]
tetetetetetetete
tetetettetetetete

rererererererere
rerererererererr