Skip to content

Instantly share code, notes, and snippets.

@Karunamon
Created March 3, 2014 18:08
Show Gist options
  • Save Karunamon/9331001 to your computer and use it in GitHub Desktop.
Save Karunamon/9331001 to your computer and use it in GitHub Desktop.
Appends month/day/year fields to CSV files - useful because you apparently can't target blog entries by title in Confluence CLI without specifying their date separately.
#!/usr/bin/env ruby
#Add date fields for mass operations on blogs with Atlassian CLI.
#WTFPL
require "csv"
fail "Specify path to input file" unless ARGV[0]
fail "Specify path to output file" unless ARGV[1]
hdr=true
CSV.open(ARGV[1], 'w') do |csv|
CSV.foreach(ARGV[0], :headers => true, :skip_blanks => true) do |row|
date = row["Created"].match(/(?<month>\d+)\/(?<day>\d+)\/(?<year>\d+)/)
row << ['month', date[:month]]
row << ['day', date[:day]]
row << ['year', date[:year]]
csv << row.headers if hdr
csv << row
hdr = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment