Skip to content

Instantly share code, notes, and snippets.

@manveru
Created April 15, 2013 07:18
Show Gist options
  • Save manveru/5386322 to your computer and use it in GitHub Desktop.
Save manveru/5386322 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
fail "Please specify a string first and then the directory second" if ARGV.size != 2
query, location = *ARGV
puts "you're looking for #{query} in #{location}"
def grep(query, file)
File.open file do |fd|
fd.each_line do |line|
puts line.chomp if line.include? query
end
end
end
puts "Results:"
if File.directory?(location)
require 'find'
Find.find(location) do |path|
grep(query, path) if File.file?(path)
end
else
grep(query, location)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment