Newbie: add few lines to file ..?

Discussion in 'Ruby' started by newman, Jan 31, 2008.

  1. newman

    newman Guest

    Hi!

    I try to write code which adding extra lines to my file

    ruby -e 'readlines.each{.......... } ' myfile_name~ > myfile_name

    How to make it. I should use readlines...?
    newman, Jan 31, 2008
    #1
    1. Advertising

  2. newman

    7stud -- Guest

    newman wrote:
    > Hi!
    >
    > I try to write code which adding extra lines to my file
    >


    File.open('data.txt', 'a') do |file|
    file.puts('hello world')
    end
    --
    Posted via http://www.ruby-forum.com/.
    7stud --, Jan 31, 2008
    #2
    1. Advertising

  3. newman

    Lee Jarvis Guest

    Re: Newbie: add few lines to file ..?

    Yeah, as 7stud says, open the file with the append flag..

    You should look through the docs of the File class, and possibly
    Google? They're suprisingly useful..

    Regards,
    Lee
    Lee Jarvis, Jan 31, 2008
    #3
  4. newman wrote:
    > I try to write code which adding extra lines to my file
    >
    > ruby -e 'readlines.each{.......... } ' myfile_name~ > myfile_name


    Replace the > with a >> and the output of your script will be appended to
    myfile_name instead of replacing it.

    HTH,
    Sebastian
    --
    Jabber:
    ICQ: 205544826
    Sebastian Hungerecker, Jan 31, 2008
    #4
    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. Replies:
    6
    Views:
    407
    John Machin
    Aug 24, 2005
  2. Murali
    Replies:
    2
    Views:
    544
    Jerry Coffin
    Mar 9, 2006
  3. Boris
    Replies:
    0
    Views:
    409
    Boris
    Jul 2, 2008
  4. Ben
    Replies:
    6
    Views:
    106
    Tim McDaniel
    Apr 16, 2009
  5. Cah Sableng
    Replies:
    0
    Views:
    231
    Cah Sableng
    Apr 23, 2007
Loading...

Share This Page