Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2015 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5526eb092b5191787b96 to your computer and use it in GitHub Desktop.
Save anonymous/5526eb092b5191787b96 to your computer and use it in GitHub Desktop.
#!/Users/tim/.rvm/rubies/ruby-2.1.5/bin/ruby
file_in = ARGV[0]
puts "importing #{file_in} . . . "
# ensure the file has the correct line breaks
system("perl -pi -e 's/\r/\n/g' #{file_in}")
out_file = "#{file_in.gsub('.txt','')}_out.csv"
File.open(out_file, 'w') do |f_w|
# use "\n" for two lines of text
File.open(file_in, "r") do |f|
f.each_line do |line|
if line =~ /^(\d{2}\/\d{2}) (.*) (\-?\d+\.\d+)/
data = "#{$1}, #{$2}, #{$3}"
f_w.puts data
puts data
end
end
end
end
puts "created #{out_file}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment