-
-
Save trailjeep/d59fc7ca7df5b0a252049d6ca5d8dc98 to your computer and use it in GitHub Desktop.
Awk script that converts iCalendar .ics files to pipe "|" separated values for further processing
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
# Adapted from [codedot/ics2tc.awk](https://gist.github.com/codedot/1cce55b4fd354b470becb8ce341b6598) | |
# Parse ics to pipe seperated values for further processing | |
# pass in vars (-v from=remove entries before this date) (-v source=add string so i know source from multiple ics's) | |
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; | |
} | |
/^BEGIN:VEVENT/ { | |
dtstart = ""; | |
dtend = ""; | |
summary = ""; | |
description = ""; | |
location = ""; | |
} | |
/^DTSTART:/ { | |
sub(/\r$/, ""); | |
sub(/^DTSTART:/, ""); | |
dtstart = parse($0); | |
} | |
/^DTEND:/ { | |
sub(/\r$/, ""); | |
sub(/^DTEND:/, ""); | |
dtend = parse($0); | |
} | |
/^SUMMARY:/ { | |
sub(/\r$/, ""); | |
sub(/^SUMMARY:/, ""); | |
gsub(/ */, " "); | |
summary = $0; | |
} | |
/^DESCRIPTION:/ { | |
sub(/\r$/, ""); | |
sub(/^DESCRIPTION:/, ""); | |
gsub(/ */, " "); | |
gsub(/\\n/, " "); | |
gsub(/\\/, ""); | |
gsub(/%nbsp;/, ""); | |
description = $0; | |
} | |
/^LOCATION:/ { | |
sub(/\r$/, ""); | |
sub(/^LOCATION:/, ""); | |
gsub(/ */, " "); | |
gsub(/\\n/, " "); | |
gsub(/\\/, ""); | |
location = $0; | |
} | |
/^END:VEVENT/ { | |
if (dtstart>=from && dtend && summary) { | |
print dtstart "|" dtend "|" source " / " summary "|" description "|" location "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment