From txt to ics
A simple sed script to convert txt files to ics
This tool converts txt files (formatted in a specific way) into ics events on a calendar. It’s mostly useless except as a good SED exercise and reference. The code is on GitHub.
USAGE
Open a terminal window, go to this directory where tl.sed and journal.txt are located and execute like this:
sed -f tl.sed journal.txt|sed ':begin;/END:VEVENT/! N;/\\n\n/s/\n//;tbegin;P;D'|sed -e '1i\BEGIN:VCALENDAR' -e '$a\END:VCALENDAR' -e 's/END:VEVENT$/\nEND:VEVENT/'
The generated ics should be ready for import to most calendars.
INPUT FILE
A ‘journal.txt’ file formatted like this
Wednesday 10:29 AM 05/24/2017
-Day of the week, then date and time in the above format.
-The dash at the beginning of each point is necessary.
. This is how I do sublists (optional)
.. And subsublists (optional)
-At least four dashes at the beginning of the line to mark the end the list, as below.
-----------------------------------------------------------------------------
Tuesday 01:08 AM 05/23/2017
-More features in this note.
-It is useful to use keyboard shortcuts for marking tasks (F3). #Task
-And projects (F4). #Project
-And mark things as done (F2). #Done!
-And (F6) for the line below.
-----------------------------------------------------------------------------
Output
Here is what you get after executing the code on the given sample file:
BEGIN:VCALENDAR
BEGIN:VEVENT
SUMMARY:TO-DO List20170524
DTSTART;VALUE=DATE:20170524
DTEND;VALUE=DATE:20170524
DESCRIPTION:\n\n-Day of the week, then date and time in the above format.\n-The dash at the beginning of each point is necessary.\n . This is how I do sublists (optional)\n .. And subsublists (optional)\n-At least four dashes at the beginning of the line to mark the end the list, as below.\n
END:VEVENT
BEGIN:VEVENT
SUMMARY:TO-DO List20170523
DTSTART;VALUE=DATE:20170523
DTEND;VALUE=DATE:20170523
DESCRIPTION:\n\n-More features in this note.\n-It is useful to use keyboard shortcuts for marking tasks (F3). #Task\n-And projects (F4). #Project \n-And mark things as done (F2). #Done!\n-And (F6) for the line below. \n
END:VEVENT
END:VCALENDAR
The SED Code
I’ll write an explanation when I have time. Here is the code for now:
1 s/\<[0-9]\>/0&/g # padding with zeros, if needed
2 s/\([0-9]\{2\}\)\/\([0-9]\{2\}\)\/\([0-9]\{4\}\)/\3\1\2/ # converting dates
3 s/[A-Z][a-z][a-z][a-z]*[a-z]*[a-z]*day ..:.. .. \(20[0-9]\{6\}\)/BEGIN:VEVENT\nSUMMARY:TO-DO List\1\nDTSTART;VALUE=DATE:\1 \nDTEND;VALUE=DATE:\1\nDESCRIPTION:/
4 /----/c\END:VEVENT\
5 /DESCRIPTION:/,/END:VEVENT/{ #edit all lines between DESCRIPTION: and END:VEVENT
6 /END:VEVENT/!{s/$/\\n/}} #if it's not the last line, replace $ with \n