From: Robert Klemme Date: 2012-08-09T21:51:45+09:00 Subject: Re: File eliminating 'a' On Thu, Aug 9, 2012 at 1:53 PM, ajay paswan wrote: > Could not understand any line.. > can we do in conventional way? > like open a file to read and then open a file to write and then write > logically, then delete source and rename the new file. Like so? 14:50:41 ~$ ruby19 rrr.rb t1.txt 14:50:45 ~$ diff -U5 t1.txt.bak t1.txt --- t1.txt.bak 2012-08-09 12:47:35.043920600 +0200 +++ t1.txt 2012-08-09 14:50:45.712765600 +0200 @@ -1,11 +1,11 @@ 111111111 -a + b -ab -ba -bab +b +b +bb "a" "b" "ab" "ba" "bab" 14:50:47 ~$ cat -n rrr.rb 1 ARGV.each do |f| 2 bak = f + ".bak" 3 File.rename f, bak 4 File.open f, 'w' do |out| 5 File.foreach bak do |line| 6 out.puts line.split(/("[^"]*")/).each {|s| /\A"/ =~ s or s.gsub!(/a/, '')}.join 7 end 8 end 9 end Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/