From 0cc20f0516969fe4fa1c5f807b921e2eabd80374 Mon Sep 17 00:00:00 2001 From: Richard Kojedzinszky Date: Mon, 6 Oct 2014 23:23:12 +0200 Subject: [PATCH] uwc: ruby implementation --- uwc.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 uwc.rb diff --git a/uwc.rb b/uwc.rb new file mode 100644 index 0000000..38deebb --- /dev/null +++ b/uwc.rb @@ -0,0 +1,16 @@ +#!/usr/bin/ruby -w + +hash = Hash.new(0) + +re = /([a-z']+)/i + +$stdin.each do |line| + line.scan(re).each do |w| + w = w[0] + hash[w] = hash[w] + 1 + end +end + +hash.keys.sort_by! { |x| [hash[x], x] }.each do |w| + puts "#{w} #{hash[w]}" +end -- 2.1.4