Last active
August 29, 2015 14:21
-
-
Save atelic/05ba7c161108f22a982d to your computer and use it in GitHub Desktop.
Ruby script that finds all TODO comments in a file or multiple files and outputs to out.txt
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 | |
if ARGV.empty? | |
puts "Please enter a file name" | |
exit | |
end | |
out_file = File.new("out.txt", "w+") | |
puts "Appending to output file..." | |
ARGV.each do |file| | |
line_num = 1 | |
out_file.puts("File: " + file + ":\n" ) | |
out_file.puts("-----------------------" + "\n" ) | |
File.readlines(file).each do |line| | |
if line.downcase.include? "todo" | |
out_file.puts("Line " + line_num.to_s + ": " + line.chomp + "\n") | |
end | |
line_num += 1 | |
end #end of loop for each line in the file | |
out_file.puts("-----------------------" + "\n" ) | |
end #end of loop for each arg | |
puts "Done! The results can be found in the out.txt file" | |
out_file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment