-
-
Save higuma/f47e9927831a38f3c242172269c6c2f0 to your computer and use it in GitHub Desktop.
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 | |
# Recursive line/word/byte counter | |
require 'find' | |
require 'fileutils' | |
ARGV.push '.' if ARGV.empty? | |
total_lines = total_words = total_bytes = 0 | |
for arg in ARGV | |
Find.find arg do |path| | |
if FileTest.file? path | |
bytes = FileTest.size path | |
contents = File::readlines(path) | |
lines = contents.size | |
words = contents.inject(0) {|result, line| result + line.split(/\s+/).size } | |
printf "%7d %8d %9d %s\n", lines, words, bytes, path | |
total_lines += lines | |
total_words += words | |
total_bytes += bytes | |
end | |
end | |
end | |
printf "%7d %8d %9d [Total]\n", total_lines, total_words, total_bytes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment