usage_quit() {
cat <<- EOF >&2
Usage:
$(basename "$0") BEGIN END FILE...
Format of BEGIN and END:
YYYY-mm-dd: the given date
-N: N days before today
+N: N days after today
EOF
exit 1
}
get_date() {
case "$1" in
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])
printf %s "$1" | tr -d -
;;
''|[!+-]*|[+-]*[!0-9]*)
return 1
;;
*)
date -I -d "$1 days" | tr -d -
;;
esac
}
[ "$#" -lt 3 ] && usage_quit
begin="$(get_date "$1")" || usage_quit
end="$(get_date "$2")" || usage_quit
shift 2
cat "$@" | grep -v -e '^#' -e '^$' | while read -r date line
do
case "$date" in
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])
numdate="$(printf %s "$date" | tr -d -)"
;;
*)
printf 'Invalid date: %s\n' "$date" >&2
continue
;;
esac
[ "$numdate" -lt "$begin" ] || [ "$numdate" -gt "$end" ] && continue
printf '%s %s\n' "$date" "$line"
done | LC_ALL=C sort
text/plain
This content has been proxied by September (ba2dc).