# awk script for converting an iCal formatted file to a sequence of org-mode headings. # this may not work in general but seems to work for day and timed events from Google's # calendar, which is really all I need right now... # # Eric S Fraga, 20100629 BEGIN { # use a colon to separate the type of data line from the actual contents FS = ":"; entry = "" headline = "" id = "" indescription = 0; } # any line that starts at the left with a non-space character is a new data field /^[A-Z]/ {indescription = 0;} # this type of entry represents a day entry, not timed, with date stamp YYYYMMDD /^DTSTART;VALUE=DATE/ { date = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]", "\\1-\\2-\\3", "g", $2) #print date } # this represents a timed entry with date and time stamp YYYYMMDDTHHMMSS # we ignore the seconds /^DTSTART:/ { #print $0 date = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])T([0-9][0-9])([0-9][0-9]).*[\r]", "\\1-\\2-\\3 \\4:\\5", "g", $2); # print date; } # The description will the contents of the entry in org-mode. # this line may be continued and as I do not know if other lines may be continued, # we only process continuation lines that come immediately after this one /^DESCRIPTION/ { entry = gensub("\r", "", "g", $2); indescription = 1; } # continuation lines (at least from Google) start with two spaces # if the continuation is after a description, append the entry /^ / { # print "** continuation line: " $0 if (indescription) { entry = entry gensub("\r", "", "g", $0); } } # the summary will be the org heading /^SUMMARY/ { headline = gensub("(.*)[\r]", "\\1", "g", $2); } # the unique ID will be stored as a property of the entry /^UID/ { id = gensub("(.*)[\r]", "\\1", "g", $2); } # when we reach the end of the event line, we output everything we # have collected so far, creating a top level org headline with the # date/time stamp, unique ID property and the contents, if any /^END:VEVENT/ { print "* " headline print " :PROPERTIES:" print " :ID: " id print " :END:" print " <" date ">" # for the entry, convert all embedded "\n" strings to actual newlines print "" print gensub("\\\\n", "\n", "g", entry); # need 4 backslash to get one in the pattern! headline = "" date = "" entry = "" indescription = 0 } END { print strftime("* COMMENT ical2org finished at [%Y-%m-%d %H:%M]"); }