From: William Morgan Date: 2005-04-20T08:34:33+09:00 Subject: Re: Modifying content in a file Excerpts from Ghislain Mary's mail of 18 Apr 2005 (EDT): > def clean_file(filename) > # Define the new caption > caption = "caption: new caption" > > # Process the content of the file > File.open(filename) do |from_file| > File.open(filename + ".new", 'w') do |to_file| > from_file.each do |line| > case > when line =~ /^caption:.*$/: line.sub!($&, caption) > end > to_file.print line > end > end > end > > # Rename the file > File.delete(filename) > File.rename(filename + ".new", filename) > end Sure, here's a two line version: def clean_file(filename) caption = "caption: new caption" system %%ruby -i -pe '$_.gsub! /^caption:.*$/,"#{caption}"' #{filename}% end (heh heh heh...) -- William