Last active
December 14, 2015 10:49
-
-
Save KB1RMA/5074676 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
#!/usr/bin/env ruby | |
# ./canada.rb amateur.txt | |
Fields = %w{call first_name last_name address city postal_code license} | |
puts Fields.join ',' | |
open(ARGV[0],:encoding=>"ISO8859-1").each_line.map{|l| | |
p = (case l.size | |
when 212 then | |
l.match /^(?<call>.{7})(?<first_name>.{36})(?<last_name>.{36})(?<address>.{71})(?<city>.{36})(?<postal_code>.{14})(?<license>.{10})/ | |
when 471 then | |
l.match /^(?<call>.{7})(?<skip>.{193})(?<license>.{10})(?<first_name>.{71})(?<last_name>.{71})(?<address>.{71})(?<city>.{36})(?<postal_code>.{11})/ | |
end) | |
puts Fields.map{|f|p[f].strip.gsub(/,/,'\,')}.join(',') if p | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment