Skip to content

Instantly share code, notes, and snippets.

@flyfy1
Last active August 11, 2020 16:05
Show Gist options
  • Save flyfy1/8e67cd271f5603a27c76da04cc556570 to your computer and use it in GitHub Desktop.
Save flyfy1/8e67cd271f5603a27c76da04cc556570 to your computer and use it in GitHub Desktop.
file for parse from `ISO 8601` date into `yyyy-MM-dd HH:mm:ss` so that it's parsable by MySQL when imported as CSV
#!/usr/bin/ruby
source_path = ARGV[0]
target_path = ARGV[1]
puts "going to process file: #{source_path}"
puts "going to create file: #{target_path}"
fail "source file non edist" unless File.exist?(source_path)
fail "target file already edist" if File.exist?(target_path)
fo = File.open(target_path, 'w')
File.foreach(source_path) do |l|
nl = l.gsub /"(?<date>\d{4}-\d{2}-\d{2})T(?<time>\d{2}:\d{2}:\d{2})Z"/, '"\k<date> \k<time>"'
fo.write(nl)
end
fo.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment