#! /bin/sh -- # # http://cryp.to/redate # # Match anything that resembles an ISO date and change it # to today. Report which files have have been changed. # # Latest release: 2009-04-22 (SCNR) # if [ $# -lt 1 ]; then echo "Usage: $0 file [file...]" exit fi today=`date --iso-8601` append_dots_to_row() { local pad n n=${2} while [ ${n} -gt 0 ]; do pad="${pad}." n=`expr ${n} - 1` done echo "${1}${pad}" | \ awk '{ printf("%s ", substr($0, 0, n)); }' n=${2} } for n in $*; do append_dots_to_row ${n} 50 sed -e "s/200[789]-[0-9][0-9]-[0-9][0-9]/${today}/g" <${n} >${n}.tmp if cmp --quiet ${n} ${n}.tmp; then rm ${n}.tmp echo "nothing" else mv ${n}.tmp ${n} echo "redated" fi done