# Removing blank lines

**URL:** <https://rubytalk.org/t/removing-blank-lines/21510>\
**Category:** ruby-talk\
**Created:** [12 October 2005 18:26 UTC](https://rubytalk.org/t/removing-blank-lines/21510 "2005-10-12T18:26:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![basi](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@basi](https://rubytalk.org/u/basi)\
**Post date:** [12 October 2005 18:26 UTC](https://rubytalk.org/t/removing-blank-lines/21510/1 "2005-10-12T18:26:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Esteban\_Manchado\_Ve1](https://avatars.discourse-cdn.com/v4/letter/e/c57346/32.png) [@Esteban\_Manchado\_Ve1](https://rubytalk.org/u/Esteban_Manchado_Ve1)\
**Post date:** [12 October 2005 18:32 UTC](https://rubytalk.org/t/removing-blank-lines/21510/2 "2005-10-12T18:32:47Z")

</div>

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 you'll  
have to write it to another, temporal file, and then move it to the original  
path.

&nbsp;&nbsp;&nbsp;&nbsp;Regards,

> **···**
>
> On Thu, Oct 13, 2005 at 03:26:52AM +0900, basi wrote:
> 
> --  
> Esteban Manchado Velázquez \<zoso@foton.es\> - [http://www.foton.es](http://www.foton.es)  
> EuropeSwPatentFree - [http://EuropeSwPatentFree.hispalinux.es](http://EuropeSwPatentFree.hispalinux.es)

---

<div class="post-metadata">

**Author:** ![W\_James](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@W\_James](https://rubytalk.org/u/W_James)\
**Post date:** [12 October 2005 21:31 UTC](https://rubytalk.org/t/removing-blank-lines/21510/3 "2005-10-12T21:31:55Z")

</div>

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.)  
> Thanks,  
> basi

awk 'NF' infile \>outfile

---

<div class="post-metadata">

**Author:** ![Nakada\_Nobuyoshi](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@Nakada\_Nobuyoshi](https://rubytalk.org/u/Nakada_Nobuyoshi)\
**Post date:** [13 October 2005 01:43 UTC](https://rubytalk.org/t/removing-blank-lines/21510/4 "2005-10-13T01:43:58Z")

</div>

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.)

&nbsp;&nbsp;grep -v ^$ infile \> outfile

To remove also lines contain whitespaces only:

&nbsp;&nbsp;grep -v '^[]\*$' infile \> outfile

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Kevin\_Bedell](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@Kevin\_Bedell](https://rubytalk.org/u/Kevin_Bedell)\
**Post date:** [12 October 2005 18:38 UTC](https://rubytalk.org/t/removing-blank-lines/21510/5 "2005-10-12T18:38:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stefan\_Lang](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Stefan\_Lang](https://rubytalk.org/u/Stefan_Lang)\
**Post date:** [12 October 2005 18:42 UTC](https://rubytalk.org/t/removing-blank-lines/21510/6 "2005-10-12T18:42:15Z")

</div>

similar:

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

Regards,  
&nbsp;&nbsp;Stefan

> **···**
>
> On Wednesday 12 October 2005 20:32, Esteban Manchado Velázquez 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 !~ /^$/}'

---

<div class="post-metadata">

**Author:** ![Stefan\_Lang](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Stefan\_Lang](https://rubytalk.org/u/Stefan_Lang)\
**Post date:** [12 October 2005 18:48 UTC](https://rubytalk.org/t/removing-blank-lines/21510/7 "2005-10-12T18:48:34Z")

</div>

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

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

Regards,  
&nbsp;&nbsp;Stefan

> **···**
>
> On Wednesday 12 October 2005 20:32, Esteban Manchado Velázquez wrote:
> 
> > On Thu, Oct 13, 2005 at 03:26:52AM +0900, basi wrote:

---

<div class="post-metadata">

**Author:** ![basi](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@basi](https://rubytalk.org/u/basi)\
**Post date:** [12 October 2005 18:51 UTC](https://rubytalk.org/t/removing-blank-lines/21510/8 "2005-10-12T18:51:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![W\_James](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@W\_James](https://rubytalk.org/u/W_James)\
**Post date:** [12 October 2005 21:36 UTC](https://rubytalk.org/t/removing-blank-lines/21510/9 "2005-10-12T21:36:53Z")

</div>

William James wrote:

> 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.)  
> \> Thanks,  
> \> basi
> 
> 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

---

<div class="post-metadata">

**Author:** ![basi](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@basi](https://rubytalk.org/u/basi)\
**Post date:** [13 October 2005 02:26 UTC](https://rubytalk.org/t/removing-blank-lines/21510/10 "2005-10-13T02:26:56Z")

</div>

Wow, so many people who'd like to help. Overwhelmed I am again. Thank  
you!  
basi

---

<div class="post-metadata">

**Author:** ![Tom\_Copeland](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@Tom\_Copeland](https://rubytalk.org/u/Tom_Copeland)\
**Post date:** [12 October 2005 18:56 UTC](https://rubytalk.org/t/removing-blank-lines/21510/11 "2005-10-12T18:56:05Z")

</div>

> 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

> **···**
>
> On Thu, 2005-10-13 at 03:38 +0900, Kevin Bedell wrote:

---

<div class="post-metadata">

**Author:** ![basi](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@basi](https://rubytalk.org/u/basi)\
**Post date:** [12 October 2005 18:56 UTC](https://rubytalk.org/t/removing-blank-lines/21510/12 "2005-10-12T18:56:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bob\_Aman2](https://avatars.discourse-cdn.com/v4/letter/b/bbce88/32.png) [@Bob\_Aman2](https://rubytalk.org/u/Bob_Aman2)\
**Post date:** [12 October 2005 19:01 UTC](https://rubytalk.org/t/removing-blank-lines/21510/13 "2005-10-12T19:01:36Z")

</div>

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

> **···**
>
> --  
> Bob Aman

---

<div class="post-metadata">

**Author:** ![basi](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@basi](https://rubytalk.org/u/basi)\
**Post date:** [12 October 2005 19:01 UTC](https://rubytalk.org/t/removing-blank-lines/21510/14 "2005-10-12T19:01:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Neukirche1](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@Christian\_Neukirche1](https://rubytalk.org/u/Christian_Neukirche1)\
**Post date:** [12 October 2005 19:14 UTC](https://rubytalk.org/t/removing-blank-lines/21510/15 "2005-10-12T19:14:32Z")

</div>

Stefan Lang \<langstefan@gmx.at\> writes:

> > 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.)
> 
> > zoso@velutha:~/tmp$ ruby -e 'puts File.readlines("test").find\_all  
> > {|line| line !~ /^$/}'
> 
> similar:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;ruby -e 'puts File.read("test").gsub(/\n{2,}/, "\n")'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ruby -e 'print File.read("t").squeeze("\n")'

Know thy tools 🙂

> **···**
>
> > On Wednesday 12 October 2005 20:32, Esteban Manchado Velázquez wrote:
> > 
> > > On Thu, Oct 13, 2005 at 03:26:52AM +0900, basi wrote:
> 
> > &nbsp;&nbsp;Stefan
> 
> --  
> Christian Neukirchen \<chneukirchen@gmail.com\> [http://chneukirchen.org](http://chneukirchen.org)

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [12 October 2005 19:36 UTC](https://rubytalk.org/t/removing-blank-lines/21510/16 "2005-10-12T19:36:54Z")

</div>

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

> **···**
>
> Kevin Bedell \<kevin@kbedell.com\> wrote:
> 
> > Also, I'd appreciate if anyone would share their opinions on the best  
> > GUI for postgres on Linux and/or Macs.

---

<div class="post-metadata">

**Author:** ![snacktime](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@snacktime](https://rubytalk.org/u/snacktime)\
**Post date:** [12 October 2005 22:15 UTC](https://rubytalk.org/t/removing-blank-lines/21510/17 "2005-10-12T22:15:39Z")

</div>

> 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 is  
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!

> **···**
>
> On 10/12/05, Kevin Bedell \<kevin@kbedell.com\> wrote:
> 
> > -k

---

<div class="post-metadata">

**Author:** ![basi](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@basi](https://rubytalk.org/u/basi)\
**Post date:** [12 October 2005 18:56 UTC](https://rubytalk.org/t/removing-blank-lines/21510/18 "2005-10-12T18:56:54Z")

</div>

Opps, that was meant for Stefan...

---

<div class="post-metadata">

**Author:** ![Daryl\_Richter](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Daryl\_Richter](https://rubytalk.org/u/Daryl_Richter)\
**Post date:** [12 October 2005 19:06 UTC](https://rubytalk.org/t/removing-blank-lines/21510/19 "2005-10-12T19:06:42Z")

</div>

Bob Aman wrote:

> > 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.  
> --  
> Bob Aman

You might want to look at Aqua Data Studio: [http://www.aquafold.com/](http://www.aquafold.com/)

> **···**
>
> --  
> Daryl

---

<div class="post-metadata">

**Author:** ![Caleb\_Tennis](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@Caleb\_Tennis](https://rubytalk.org/u/Caleb_Tennis)\
**Post date:** [12 October 2005 19:52 UTC](https://rubytalk.org/t/removing-blank-lines/21510/20 "2005-10-12T19:52:14Z")

</div>

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

Caleb

> **···**
>
> On Wednesday 12 October 2005 02:01 pm, Bob Aman wrote:
> 
> > \> 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.

[Next page](https://rubytalk.org/t/removing-blank-lines/21510.md?page=2)
