On Thu, Aug 9, 2012 at 1:53 PM, ajay paswan <[email protected]> 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/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to