Skip to content

Instantly share code, notes, and snippets.

@dpritchett
Created April 28, 2011 16:05
Show Gist options
  • Save dpritchett/946651 to your computer and use it in GitHub Desktop.
Save dpritchett/946651 to your computer and use it in GitHub Desktop.
Line count of daily logfiles in a given folder
#!/usr/bin/ruby
require 'date'
PATH = "//server_name/and/folder_path/redacted"
EXTENSION = 'txt'
# Parse out a date from each filename, print per-day line counts
Dir["#{PATH}/*.#{EXTENSION}"].each do |log_file|
return_value = ''
date_string = /\d{8}/.match(log_file).to_s
return_value << Date.parse(date_string).strftime("%Y/%m/%d\t")
open(log_file) { |f| return_value << f.lines.count.to_s }
puts return_value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment