From: William James Date: 2006-02-08T05:43:22+09:00 Subject: Re: Grep via Ruby ralf wrote: > Hi, > I'd like to have a "grep" with case-insensitive match. normal grep does > not have this functionality (afaik), but ruby does. So this is, what i > wrote: > > cat rgrep: > #!/usr/bin/env ruby > # Grep with full regexp-functionality via ruby > > if ARGV.shift == "-p" > pattern = Regexp.new(ARGV.shift) > else > puts "Please give me a pattern with the '-p' option" > exit > end > ARGV.each do |filename| > File.open(filename) do |file| > file.each do |line| > puts "#{filename} #{file.lineno.to_s}: #{line}" if > pattern.match(line) > end > end > end > > Using it via: rgrep -p '/delete /i' *.php does not match anything, but > this > #!/usr/bin/env ruby > # Grep with full regexp-functionality via ruby > > if ARGV.shift == "-p" > pattern = Regexp.new(ARGV.shift) > else > puts "Please give me a pattern with the '-p' option" > exit > end > ARGV.each do |filename| > File.open(filename) do |file| > file.each do |line| > puts "#{filename} #{file.lineno.to_s}: #{line}" if /delete > /i.match(line) > end > end > end > > DOES match. Does anyone see the bug? Maybe this can be done a lot > easier by using ARGF?? if ARGV.shift == "-p" pattern = Regexp.new(ARGV.shift,Regexp::IGNORECASE) else puts "Please give me a pattern with the '-p' option" exit end puts "#{$FILENAME} #{$.}: #{$_}" if $_ =~ pattern while gets