Skip to content

Instantly share code, notes, and snippets.

@KB1RMA
Last active December 14, 2015 10:49
Show Gist options
  • Save KB1RMA/5074676 to your computer and use it in GitHub Desktop.
Save KB1RMA/5074676 to your computer and use it in GitHub Desktop.
#!/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