From: Robert Klemme Date: 2007-04-28T21:55:04+09:00 Subject: Re: Editing a text file On 28.04.2007 02:15, barjunk wrote: > There is a task to edit a text file. It is entirely possible that > multiple people are going to be running the ruby script that edits > this file at the same time. > > I have looked at Ruby cookbook recipe 6.13 and 20.11. These seem like > what I am wanting. > > It seemed like a good idea to float this as a solution before it is > implemented. > > How I do it now is using sed: > > flock $USERFILE sed -i \ > "/^$1[[:space:]]\+/,+6 { s/^\\(.*Default\\)/#\\1/; s/^#\\(.*SRT\\)/\ > \1/; }" \ > $USERFILE > > But I'd like to move this piece of code into the ruby script instead > of launching it with a system command. > > What other ways are people doing this sort of thing? > > BTW, for those of you that don't have the cookbook, it basically > redefines open to include a flock call. I consider Ara the definitive source especially when it comes to flock'ing NFS mounted files, see for example: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/97211 For the low profile solution check out http://ruby-doc.org/core/classes/File.html#M002576 Kind regards robert