Skip to content

Instantly share code, notes, and snippets.

@paulkmiller
Created June 24, 2016 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulkmiller/7798d95ad8afcb28174b0f26bb3bd79a to your computer and use it in GitHub Desktop.
Save paulkmiller/7798d95ad8afcb28174b0f26bb3bd79a to your computer and use it in GitHub Desktop.
file_path = ARGV[0] || "test.txt"
file = File.open(file_path, "r")
line_count = File.foreach(file_path).inject(0) {|c, line| c+1}
words_count = []
lines = File.readlines(ARGV[0] || "test.txt")
text = lines.join
char_count = text.length
file.each_line do |line|
words = line.split
words.each do |word|
word = word.gsub(/[,()'"]/,'')
end
words_count << words.length
end
puts "Number of Lines: #{line_count}"
puts "Number of Words: #{words_count.inject(0){|sum,item| sum + item}}"
puts "Number of Characters: #{char_count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment