Removing blank lines

Discussion in 'Ruby' started by basi, Oct 12, 2005.

  1. basi

    basi Guest

    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
    basi, Oct 12, 2005
    #1
    1. Advertising

  2. 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 <> - http://www.foton.es
    EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es
    Esteban Manchado Velázquez, Oct 12, 2005
    #2
    1. Advertising

  3. basi

    Kevin Bedell Guest

    best resource for postgres/rails setup

    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
    Kevin Bedell, Oct 12, 2005
    #3
  4. basi

    Stefan Lang Guest

    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
    Stefan Lang, Oct 12, 2005
    #4
  5. basi

    Stefan Lang Guest

    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
    Stefan Lang, Oct 12, 2005
    #5
  6. basi

    basi Guest

    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
    basi, Oct 12, 2005
    #6
  7. basi

    basi Guest

    To Stefan and Kevin,
    Thank you much for taking the time to reply. Much appreciated.
    basi
    basi, Oct 12, 2005
    #7
  8. basi

    basi Guest

    Opps, that was meant for Stefan...
    basi, Oct 12, 2005
    #8
  9. basi

    Tom Copeland Guest

    Re: best resource for postgres/rails setup

    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
    Tom Copeland, Oct 12, 2005
    #9
  10. basi

    basi Guest

    Re: best resource for postgres/rails setup

    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, ...
    basi, Oct 12, 2005
    #10
  11. basi

    Bob Aman Guest

    Re: best resource for postgres/rails setup

    > 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
    Bob Aman, Oct 12, 2005
    #11
  12. Re: best resource for postgres/rails setup

    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/

    --
    Daryl
    Daryl Richter, Oct 12, 2005
    #12
  13. Re: best resource for postgres/rails setup

    Kevin Bedell <> wrote:
    >
    > 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
    Martin DeMello, Oct 12, 2005
    #13
  14. basi

    Caleb Tennis Guest

    Re: best resource for postgres/rails setup

    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.


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

    Caleb
    Caleb Tennis, Oct 12, 2005
    #14
  15. Christian Neukirchen wrote:

    > Stefan Lang <> writes:
    >
    >>similar:
    >>
    >> ruby -e 'puts File.read("test").gsub(/\n{2,}/, "\n")'

    >
    > 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
    Simon Kröger, Oct 12, 2005
    #15
  16. 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
    William James, Oct 12, 2005
    #16
  17. 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
    William James, Oct 12, 2005
    #17
  18. basi

    snacktime Guest

    Re: best resource for postgres/rails setup

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

    On 10/12/05, 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.



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


    ------=_Part_5348_26770557.1129143395630--
    snacktime, Oct 12, 2005
    #18
  19. 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

    --
    Nobu Nakada
    nobuyoshi nakada, Oct 13, 2005
    #19
  20. basi

    basi Guest

    Wow, so many people who'd like to help. Overwhelmed I am again. Thank
    you!
    basi
    basi, Oct 13, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NNTP
    Replies:
    2
    Views:
    943
    rakesh sharma
    Apr 7, 2004
  2. Replies:
    0
    Views:
    459
  3. Jeff
    Replies:
    3
    Views:
    9,134
    kleinbaas
    Apr 13, 2010
  4. Replies:
    6
    Views:
    2,213
  5. Cah Sableng
    Replies:
    0
    Views:
    236
    Cah Sableng
    Apr 23, 2007
Loading...

Share This Page