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…?
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs