Created
October 20, 2009 21:36
-
-
Save sms420/214639 to your computer and use it in GitHub Desktop.
ruby de dupe
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
| # 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