From: Kristof Bastiaensen Date: 2004-08-19T18:41:03+09:00 Subject: Re: Ruby way to update file lines On Thu, 19 Aug 2004 01:44:10 +0000, Mark Probert wrote: > Hi. > > I have a need to update a config file. It uses '#' as a line comment > marker. The config file looks like: > > # file comment > # > name1:foo1:bar:other > name2:foo2:bar:other > name3:foo3:bar:other > name4:foo4:bar:other > > The name:foo combination is unique. > > What is the most efficient way to read in the file, update the line, and > then write it back to the file. One update would be to place a '#' in col > 1 > > #name3:foo3:bar:other > > Any thoughts appreciated. > > -mark. You could use inplace edit. This can make ruby work like awk. For example: ruby -aF: -ni.bak -e 'print "#" if $F[0] == "name3"' configfile KB