Skip to content

Instantly share code, notes, and snippets.

@sms420
Created October 20, 2009 21:36
Show Gist options
  • Select an option

  • Save sms420/214639 to your computer and use it in GitHub Desktop.

Select an option

Save sms420/214639 to your computer and use it in GitHub Desktop.
ruby de dupe
# dedupe.rb
# Sean Stephenson
# 2009-10-20
#################################
# #
# takes one file as input. #
# reads a line and writes #
# this line to output file #
# if and only if that line #
# is unique (i.e. the line #
# exists nowhere else in #
# the input file.) #
# #
#################################
h = Hash.new
in = File.new('in.txt')
while (str = in.gets)
str.chomp!
h[str]!=nil ? h[str]+=1 : h.merge!({str => 0})
end
out = File.new('out.txt', 'w+')
h.each do |key, value|
out.puts "#{key}" if value == 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment