Skip to content

Instantly share code, notes, and snippets.

@agmcleod
Created February 10, 2011 20:50
Show Gist options
  • Save agmcleod/821317 to your computer and use it in GitHub Desktop.
Save agmcleod/821317 to your computer and use it in GitHub Desktop.
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