Last active
August 11, 2020 16:05
-
-
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
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/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