Last active
September 12, 2021 21:20
-
-
Save codedot/1cce55b4fd354b470becb8ce341b6598 to your computer and use it in GitHub Desktop.
Awk script that converts iCalendar .ics files to Time Clock "timelog" format by John Wiegley
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
function parse(dt) | |
{ | |
Y = substr(dt, 1, 4); | |
M = substr(dt, 5, 2); | |
D = substr(dt, 7, 2); | |
h = substr(dt, 10, 2); | |
m = substr(dt, 12, 2); | |
s = substr(dt, 14, 2); | |
return Y "/" M "/" D " " h ":" m ":" s; | |
} | |
/^BEGIN:VEVENT/ { | |
dtstart = ""; | |
dtend = ""; | |
summary = ""; | |
} | |
/^DTSTART:/ { | |
sub(/\r$/, ""); | |
sub(/^DTSTART:/, ""); | |
dtstart = parse($0); | |
} | |
/^DTEND:/ { | |
sub(/\r$/, ""); | |
sub(/^DTEND:/, ""); | |
dtend = parse($0); | |
} | |
/^SUMMARY:/ { | |
sub(/\r$/, ""); | |
sub(/^SUMMARY:/, ""); | |
gsub(/ */, " "); | |
summary = $0; | |
} | |
/^END:VEVENT/ { | |
if (dtstart && dtend && summary) { | |
print "i " dtstart " " prefix summary; | |
print "o " dtend; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, just what I needed to get started parsing ics to a custom text format!