Skip to content

Instantly share code, notes, and snippets.

@xrat
Created May 5, 2012 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xrat/2605649 to your computer and use it in GitHub Desktop.
Save xrat/2605649 to your computer and use it in GitHub Desktop.
Shorter Future Tasks.awk
#!/usr/bin/awk -f
#
# Original script by Ed Blackman, posted May 12, 2009, at
# http://tech.groups.yahoo.com/group/todotxt/message/2299
#
# Ruthlessly reduced by Andreas Schamanek in May, 2012.
#
# This script relies on the fact that a lexical sort of YYYY-MM-DD
# date strings produces the same result as a calendar sort, but avoids
# the tricky calendar math. It will *not* work for other types of
# date string.
BEGIN {
# today's date in a t:YYYY-MM-DD datestring
TODAY = strftime("t:%Y-%m-%d")
# the date format needs to reflect the regular expression
DATEREGEX="t:[0-9][0-9][0-9][0-9]-(0?[0-9]|1[0-2])-([0-2]?[0-9]|3[01])"
}
{
# if t:YYYY-MM-DD is found, and the date (substr) is in the future
# skip the line (next) else print it
if (match($0, DATEREGEX) && (substr($0, RSTART, RLENGTH) > TODAY)) next
else print
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment