Skip to content

Instantly share code, notes, and snippets.

@putnamhill
Created February 23, 2019 23:03
Show Gist options
  • Save putnamhill/e4d8a6d68d2e0423d861ce043d5fe0c3 to your computer and use it in GitHub Desktop.
Save putnamhill/e4d8a6d68d2e0423d861ce043d5fe0c3 to your computer and use it in GitHub Desktop.
an awk script to convert Apple's reminder lists to plain text
#!/usr/bin/env awk -f
BEGIN {
FS = ":"
RS = "\r\n"
OFS = "\t"
}
/BEGIN:VTODO/ {
my_status = ""
my_summary = ""
}
FNR == 1 {
# print the filename in uppercase as a header
ics_name = toupper(FILENAME)
# basename the path
sub(/.*\//, "", ics_name)
# strip file extension
sub(/\.[^\.]+$/, "", ics_name)
print ics_name
}
{
# remove .ics escaping
gsub(/\\/, "")
}
$1 == "SUMMARY" {
my_summary = $2
# join multi line entries
# any subsequecutive lines beginning with a space is extra text
getline
while (substr($0, 1, 1) == " ") {
my_summary = sprintf("%s%s", my_summary, substr($0, 2, length($0)))
getline
}
}
$1 == "STATUS" {
my_status = $2
}
/END:VTODO/ {
if (my_status != "COMPLETED") {
print "[ ]", my_summary
}
}
/END:VCALENDAR/ {
print ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment