Skip to content

Instantly share code, notes, and snippets.

@morganp
Last active December 19, 2015 15:18
Show Gist options
  • Save morganp/5974881 to your computer and use it in GitHub Desktop.
Save morganp/5974881 to your computer and use it in GitHub Desktop.
Old blogpost had formatting destroyed by google.
#!/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