Created
January 8, 2012 12:16
-
-
Save vsushkov/1578162 to your computer and use it in GitHub Desktop.
flatprocessor
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
| #!/usr/bin/env ruby | |
| file = File.open(ARGV[0], 'r') | |
| lines = Array.new | |
| file.each do |line| | |
| lines << line | |
| end | |
| phones = Array.new | |
| lines.each do |line| | |
| line.gsub(/\d+-\d+-\d+-\d+-\d+/).each do |phone| | |
| phones << phone | |
| end | |
| end | |
| duplicated_phones = Hash.new(0) | |
| phones.each do |phone| | |
| duplicated_phones[phone] += 1 | |
| end | |
| duplicated_phones.reject! {|phone, occurances| occurances == 1} | |
| result = Array.new | |
| lines.each do |line| | |
| line_contains_duplicated_phone = false | |
| duplicated_phones.each do |phone, occurances| | |
| line_contains_duplicated_phone = true if line.match(phone) | |
| end | |
| result << line unless line_contains_duplicated_phone | |
| end | |
| new_filename = 'clean_' + ARGV[0] | |
| new_file = File.open(new_filename, 'w') | |
| result.each{|result_line| new_file.print result_line} | |
| puts 'Result file is ' + new_filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment