Created
July 27, 2015 15:30
-
-
Save jcromartie/1e54d022ed13da8acdda to your computer and use it in GitHub Desktop.
uniq live!
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/ruby | |
# uniq-live | |
# | |
# Reads from stdin or a given file and counts the number of times a | |
# given line repeats as it is read. | |
last = nil | |
count = 1 | |
while !ARGF.eof? && line = ARGF.readline.strip do | |
if last == line | |
count = count.next | |
print "\r(#{count}) #{line}" | |
else | |
print "\n" if last | |
print line | |
last = line | |
count = 1 | |
end | |
end | |
print "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment