Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Produces a unique word list of a text file
- unless ARGV[0]
- puts "USAGE: ruby unique_words.rb <<text file>>"
- exit 1
- end
- file = File.new( File.expand_path( ARGV[0] ) )
- @words = []
- file.readlines.join.split.each do |word|
- @words << word.gsub(/[^\w]/, "")
- end
- puts @words.uniq!, "" if ARGV[1]
- puts "#{@words.length} unique words in #{file.path.split("/").last}"
Add Comment
Please, Sign In to add comment