Skip to content

Instantly share code, notes, and snippets.

@codedot
Last active September 12, 2021 21:20
Show Gist options
  • Save codedot/1cce55b4fd354b470becb8ce341b6598 to your computer and use it in GitHub Desktop.
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
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;
}
}
@trailjeep
Copy link

trailjeep commented Sep 12, 2021

Thank you, just what I needed to get started parsing ics to a custom text format!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment