Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment