Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Removing blank lines

Reply
Thread Tools

Removing blank lines

 
 
basi
Guest
Posts: n/a
 
      10-12-2005
Hello,
How does one delete blank lines from a text file? (I did try a number
of things, but, I can't get any to work.)
Thanks,
basi

 
Reply With Quote
 
 
 
 
Esteban Manchado Velázquez
Guest
Posts: n/a
 
      10-12-2005
Hello Basi,

On Thu, Oct 13, 2005 at 03:26:52AM +0900, basi wrote:
> Hello,
> How does one delete blank lines from a text file? (I did try a number
> of things, but, I can't get any to work.)


---------------------------------- 8< ----------------------------------
zoso@velutha:~/tmp$ cat >test
one

two



three
four

five
zoso@velutha:~/tmp$ ruby -e 'puts File.readlines("test").find_all {|line|=
line !~ /^$/}'
one
two
three
four
five
---------------------------------- >8 ----------------------------------

Or you mean writing back the result to the file? In that case, I guess yo=
u'll
have to write it to another, temporal file, and then move it to the origi=
nal
path.

Regards,

--=20
Esteban Manchado Vel=E1zquez <(E-Mail Removed)> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es


 
Reply With Quote
 
 
 
 
Kevin Bedell
Guest
Posts: n/a
 
      10-12-2005
Can anyone share their opinions on the best resource for information
on rails/postgres config and setup? I'd prefer to not use MySQL due
to licensing issues.

Also, I'd appreciate if anyone would share their opinions on the best
GUI for postgres on Linux and/or Macs.

Thanks!
-k


 
Reply With Quote
 
Stefan Lang
Guest
Posts: n/a
 
      10-12-2005
On Wednesday 12 October 2005 20:32, Esteban Manchado Vel=E1zquez wrote:
> Hello Basi,
>
> On Thu, Oct 13, 2005 at 03:26:52AM +0900, basi wrote:
> > Hello,
> > How does one delete blank lines from a text file? (I did try a
> > number of things, but, I can't get any to work.)


> zoso@velutha:~/tmp$ ruby -e 'puts File.readlines("test").find_all
> {|line| line !~ /^$/}'


similar:

ruby -e 'puts File.read("test").gsub(/\n{2,}/, "\n")'

Regards,
Stefan


 
Reply With Quote
 
Stefan Lang
Guest
Posts: n/a
 
      10-12-2005
On Wednesday 12 October 2005 20:32, Esteban Manchado Vel=E1zquez wrote:
> Hello Basi,
>
> On Thu, Oct 13, 2005 at 03:26:52AM +0900, basi wrote:
> > Hello,
> > How does one delete blank lines from a text file? (I did try a
> > number of things, but, I can't get any to work.)

[...]
> Or you mean writing back the result to the file? In that case, I
> guess you'll have to write it to another, temporal file, and then
> move it to the original path.


Without tempfile:

ruby -e 'text =3D File.read "text"; open "text", "w" do |f| f <<=20
text.gsub(/\n{2,}/, "\n") end'

Regards,
Stefan


 
Reply With Quote
 
basi
Guest
Posts: n/a
 
      10-12-2005
Thanks much! Yes, I'd have to use a temporary file, but there are
examples of this in the cookbook and I should be able to follow them
Cheers!
basi

 
Reply With Quote
 
basi
Guest
Posts: n/a
 
      10-12-2005
To Stefan and Kevin,
Thank you much for taking the time to reply. Much appreciated.
basi

 
Reply With Quote
 
basi
Guest
Posts: n/a
 
      10-12-2005
Opps, that was meant for Stefan...

 
Reply With Quote
 
Tom Copeland
Guest
Posts: n/a
 
      10-12-2005
On Thu, 2005-10-13 at 03:38 +0900, Kevin Bedell wrote:
> Can anyone share their opinions on the best resource for information
> on rails/postgres config and setup? I'd prefer to not use MySQL due
> to licensing issues.


I've been running PostgreSQL 8 and Rails on Linux for a month or so with
the pure Ruby driver; all seems well. Any particular area causing
problems?

> Also, I'd appreciate if anyone would share their opinions on the best
> GUI for postgres on Linux and/or Macs.


Can't help there, I've just been using psql...

Yours,

Tom




 
Reply With Quote
 
basi
Guest
Posts: n/a
 
      10-12-2005
Yeah, same here, I'd go for Sqlite3 or Postgres. I just got Sqlite3
gem-installed and am just about ready to try it. Then I saw Instrant
Rails, which uses MySql and I'm now downloading it. Decisions,
decisions, ...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie: css & "removing blank line between paragraphs" Jeff HTML 3 04-13-2010 09:27 AM
blank CD-R and blank DVD-R not recognized by Vista 64 Ultimate =?Utf-8?B?R3JlZyBLaXJrcGF0cmljaw==?= Windows 64bit 13 11-07-2007 12:23 PM
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
removing replacing blank lines in ASP.NET (VB) jason@cyberpine.com ASP .Net 0 05-04-2004 03:36 PM



Advertisments