Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.