Removing blank lines

B

basi

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
 
E

Esteban Manchado Velázquez

Hello Basi,

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 <[email protected]> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es
 
K

Kevin Bedell

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
 
S

Stefan Lang

Hello Basi,

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
 
B

basi

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
 
B

basi

To Stefan and Kevin,
Thank you much for taking the time to reply. Much appreciated.
basi
 
T

Tom Copeland

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
 
B

basi

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, ...
 
B

Bob Aman

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

Please, please, please tell me someone knows of a better frontend for
postgres for OS X than BiggerSQL and pgAdmin3.

I've been inflicting those two upon myself for far too long now.
 
M

Martin DeMello

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

I've been pretty happy with pgadmin3, though pgaccess was easier to get
up and running from source (pgadmin3 requires a unicode-enabled wxGTK -
if you're using gentoo, you need to update your binutils before
compiling it). Nothing equivalent to dbdesigner4, sadly.

martin
 
C

Caleb Tennis

Please, please, please tell me someone knows of a better frontend for
postgres for OS X than BiggerSQL and pgAdmin3.

phppgadmin is what I use here, and I'm very happy with it.

Caleb
 
S

Simon Kröger

Christian said:
ruby -e 'print File.read("t").squeeze("\n")'

Know thy tools :)

Yep!

ruby -i.bak -ple 'next if $_==""' test

Inplace editing with backup file.

cheers

Simon
 
W

William James

basi said:
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

awk 'NF' infile >outfile
 
W

William James

William said:
awk 'NF' infile >outfile

Here's another. Remove blank lines (lines that are empty or contain
only whitespace) from beginning of file. After first non-blank line,
keep all remaining lines.

awk 'NF,0' infile >outfile
 
S

snacktime

------=_Part_5348_26770557.1129143395630
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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.


There really isn't anything different about using postgresql other than the
parameters in database.yml. There is some stuff in the how to sections on
the websites about using views, etc..

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


pgadmin is good, clean, simple, lightweight.. EMS postgresql manager lite i=
s
probably the best free gui, although I prefer pgadmin because it's lighter
and I don't need all the features of EMS postgresql manager.

Chris


Thanks!

------=_Part_5348_26770557.1129143395630--
 
N

nobuyoshi nakada

Hi,

At Thu, 13 Oct 2005 03:26:52 +0900,
basi wrote in [ruby-talk:160238]:
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.)

grep -v ^$ infile > outfile

To remove also lines contain whitespaces only:

grep -v '^[ ]*$' infile > outfile
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top