Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created July 27, 2015 15:30
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 jcromartie/1e54d022ed13da8acdda to your computer and use it in GitHub Desktop.
Save jcromartie/1e54d022ed13da8acdda to your computer and use it in GitHub Desktop.
uniq live!
#!/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