Newbie: add few lines to file ..?

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

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

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