Rewrite data to a file

rewrite data to a file.

I have a file with the following data

1!name!registration!login

This means that 1 “is written on file” when
receive the login keyboard have to replace that
1 0, which would be the logical exclusion. Does anyone know
how do you rewrite data in ruby?

Thank you very much!

On Thu, Mar 24, 2011 at 4:29 PM, Joyce L. [email protected] wrote:

I have a file with the following data

1!name!registration!login

This means that 1 “is written on file” when
receive the login keyboard have to replace that
1 0, which would be the logical exclusion. Does anyone know
how do you rewrite data in ruby?

Are you able to write a (new) file with the correct data?

Generally, the safe way to update a file is to read from the old file,
write to a temporary file, and move the temporary file over the old
file.

  • Are all of the updates you need to make of the form: 0 <-> 1
  • How often do you need to update the file
  • When you update the file, how many updates are made
  • How large is your file (tens of lines or thousands or billions)

The syntax for opening the file would be:

File.open(’/path/to/file’).write{ |f| f.write(‘some data’) }

On Fri, Mar 25, 2011 at 1:04 AM, Emil K. [email protected] wrote:

The syntax for opening the file would be:

File.open(’/path/to/file’).write{ |f| f.write(‘some data’) }

Note for Windows users:

File.open “c:/path with spaces to/file.name”

and

File.open “C:\path with spaces to\file.name”

are equally valid (Windows accepts both forward- and backslashes in
paths these days).


Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

look at gsub.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs