Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Newbie: add few lines to file ..?

Reply
Thread Tools

Newbie: add few lines to file ..?

 
 
newman
Guest
Posts: n/a
 
      01-31-2008
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...?
 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      01-31-2008
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/.

 
Reply With Quote
 
 
 
 
Lee Jarvis
Guest
Posts: n/a
 
      01-31-2008
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
 
Reply With Quote
 
Sebastian Hungerecker
Guest
Posts: n/a
 
      01-31-2008
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: http://www.velocityreviews.com/forums/(E-Mail Removed)
ICQ: 205544826

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XInclude a few lines of a text file? Boris XML 0 07-02-2008 10:58 PM
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
To delete few lines and add few lines at the end of a text file using c program Murali C++ 2 03-09-2006 04:45 PM
Reading just a few lines from a text file tkpmep@hotmail.com Python 6 08-23-2005 11:11 PM
Re: how to read 10 lines from a 200 lines file and write to a new file?? Joe Wright C Programming 0 07-27-2003 08:50 PM



Advertisments