Created
July 2, 2013 01:58
-
-
Save mzemel/5906258 to your computer and use it in GitHub Desktop.
Messily cleans cities
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
cities_array = IO.readlines('cities.txt') | |
cities_array.each do |entry| | |
entry.gsub!("\\n","") | |
entry.gsub!("{\"Name\":\"","") | |
entry.gsub!(/\",\"Type\":\"City\",\"BID\":null,\"City\":null,\"State\":\"..\"}/,"") | |
entry.gsub!("][","],[") | |
end | |
cities_array = cities_array.first.split(",").select{ |i| i != "[]" } | |
cities_array.each do |city| | |
city.gsub!("[","") | |
city.gsub!("]","") | |
puts city | |
end | |
puts cities_array.size.to_s + " cities counted." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment