From: dblack@... Date: 2007-08-26T20:59:38+09:00 Subject: Re: Finding one certain line in a file is easy but how to look for headlines and something just under this certain headline? Hi -- On Sun, 26 Aug 2007, kazaam wrote: > Hi, > I'm writing a little script for installing ati-drivers on linux > machines but I have a little problem. I need to change the > /etc/X11/xorg.conf file for this. This file is built like this (just > a cut-out): > > Section "InputDevice" > > Now I need to change the driver value within the Section "Device" > from ati|vesa|radeon|nomatterwhat... to fglrx, but how to find it? > E.g. IO.foreach('/etc/X11/xorg.conf') { |line| puts line if line =~ > /^Section "Device"/ } finds me the correct section but how to > "navigate" now in it? Is iteration at all the answer to this > problem? I usually do something like this (where fh is my filehandle): while line = fh.gets flag = true if /Section "Device"/.match(line) flag = false if flag && line.gsub!(/(Driver\s+)"(.*)"/, '\1"fglrx"') puts line end David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)