txt2when - generate entries for When from text files with birthdays

txt2when.sh

Suppose you have separate text files with the birthdays of your friends (and maybe some other information, e.g. addresses), like so:

This script turns them into output that can be used by When and prints it to stdout, like so:

For more info on When, see:

https://www.lightandmatter.com/when/when.html

Behavior

The script recursively looks for files in the current directory that contain a line of the format “* YYYY-mm-dd”. “mm” and “dd” need to be decimal digits. If “YYYY” consists of decimal digits, the script uses it as the birth year. Otherwise, it assumes the birth year is unknown. To indicate that, you can use something like “XXXX” or “????” or even “197X” or “197?”, but they need to be 4 characters.

The script prints the names of all files that do not contain such a line to stderr. If, for some reason, multiple birthday lines are found in the same file, they are treated as separate birthdays for the same person (or at least for people with the same name).

The script uses the name of a file as the person’s name. The ending (a dot followed by anything) is removed and all dashes and underscores are replaced with spaces. All directories above the file, if any, put into parantheses after the name. Dashes and underscores are replaced with spaces, but the slashes separating the directories in the path are kept.

The script sorts its output by the months, then by the days, then by the names. Years are not considered.

EOF