Created
April 15, 2013 07:18
-
-
Save manveru/5386322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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