Friday, July 8, 2011

Windows batch script timestamps from gAWK

# This uses GNU Awk to emit a script to set an environment variable to the current date and time in a format suitable for use as a filename.
# See http://www.gnu.org/software/gawk/manual/
# You should supply two variables:
# 1) output_filename
# 2) env_var
BEGIN {
format = "%Y%m%d_%H%M%S"
print "set " env_var "=" strftime(format) > output_filename
}


Invoke with something like

gawk -v "output_filename=tsgenerated.bat" -v "env_var=TS" -f dt.awk
call tsgenerated.bat