Created
February 10, 2011 20:50
-
-
Save agmcleod/821317 to your computer and use it in GitHub Desktop.
This file contains 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
text = IO.read('zips.csv') | |
def add_leading(zip) | |
if zip.size < 5 | |
t = 5 - zip.size | |
t.times do | |
zip = "0#{zip}" | |
end | |
end | |
zip | |
end | |
zips = [] | |
File.open('zipsout.txt', 'w+') do |f| | |
text.split(/\n/).each do |line| | |
line.split(/\,/).each do |zip| | |
zip = zip.gsub(/\n|\t|\s/, '') | |
unless zip.match(/[0-9]{1,5}/).nil? | |
unless zips.include?(zip) | |
f.write("#{add_leading(zip)}\n") | |
zips << zip | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment