Last active
December 19, 2015 15:18
-
-
Save morganp/5974881 to your computer and use it in GitHub Desktop.
Old blogpost had formatting destroyed by google.
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 | |
#Array of Files containing matching text | |
matchingFiles = [] | |
## Build list of matching files | |
Dir.foreach("./") do |x| | |
if File.file?(x) | |
begin | |
file = File.new(x, "r") | |
while (line = file.gets) | |
#Check for first command line argument | |
if line =~ /#{ARGV[0]}/ | |
matchingFiles |= [x] | |
end | |
end | |
file.close | |
rescue => err | |
puts "Exception: #{err}" | |
err | |
end | |
end | |
end | |
## Now go back through All files and dont print the ones in the matching list | |
Dir.foreach("./") do |x| | |
if File.file?(x) | |
##File containg string | |
#if not matchingFiles.rindex(File.basename(x)).nil? | |
# puts(" #{matchingFiles.rindex(File.basename(x))}: #{x} ") | |
#end | |
if not x =~ /^\./ | |
#Files not containing String | |
if matchingFiles.rindex(File.basename(x)).nil? | |
puts("#{x}") | |
#Format for copy & paste | |
#puts(" rm \"#{x}\" ") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment