[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie: add few lines to file ..?

newman

1/31/2008 1:33:00 PM

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...?
3 Answers

7stud --

1/31/2008 2:31:00 PM

0

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

Lee Jarvis

1/31/2008 2:46:00 PM

0

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

Sebastian Hungerecker

1/31/2008 2:55:00 PM

0

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: sepp2k@jabber.org
ICQ: 205544826