ajay paswan wrote in post #1071764:
> How can I eliminate every 'a' in a file if it is not inside double
> quote?
>
> For example:
>
> input:"acb"gha"abc"
> output:"acb"gh"abc"
>
> Or simply how can I copy file character by character?

IO#getc:

while ch = STDIN.getc
  print "<#{ch}>"
end

But if your input is line-based, you're probably better off processing a 
line at a time.

A simple approach would be to split on double-quote, and then remove 'a' 
from every other field, then join them back together.

>> line = '"acb"gha"abc"'
=> "\"acb\"gha\"abc\""
>> a = line.split('"')
=> ["", "acb", "gha", "abc"]
>> 0.step(a.size-1,2) { |i| a[i].gsub!(/a/,'') }
=> 0
>> puts a.join('"')
"acb"gh"abc
=> nil

A bit of care is needed for the trailing double-quote though, because 
split doesn't give you an empty field on the end. You could add a 
trailing space then trim it off again at the end.

-- 
Posted via http://www.ruby-forum.com/.