[OS X TeX] Re: Save date-time, not Print date
Robert Bruner
rrb at math.wayne.edu
Sun Jan 7 12:41:01 EST 2007
Thanks to Victor Ivrii for showing us how easy this is:
> > \immediate\write18{ls -l \file.tex | cut -b33-45 > \file.date}
> > \input\file.date
Several comments:
1. ls -l gives variable results, viz
rrb% ls -l
total 2720
-rw-r--r-- 1 rrb wheel 1288 Jun 7 2006 L2.txt
drwx------ 31 rrb rrb 1054 Jan 5 10:55 Library/
Note that one entry is Jun 7 2006, the other is Jan 5 10:55.
This is why I suggested ls -lT.
rrb% ls -lT
total 2720
-rw-r--r-- 1 rrb wheel 1288 Jun 7 12:20:57 2006 L2.txt
drwx------ 31 rrb rrb 1054 Jan 5 10:55:45 2007 Library/
We get uniform results from which we can confidently extract the
year rather than time of day.
2. If file.date aready exists, the redirection ( ... > \file.date)
will fail. Appending is not in order, so it would seem necessary to
remove file.date before writing to it.
3. awk allows easy rewriting of the order of the parts of the date,
e.g. (and incorporating removal of file.date
\immediate\write18{rm -f \file.date; ls -lT \file.tex | awk '{print $8" "$7" "$6" "$9}' > \file.date}
will rewrite
-rw-r--r-- 1 rrb wheel 1288 Jun 7 12:20:57 2006 L2.txt
as
12:19:06 10 Dec 2006
Naturally, you may have your wn preference for the order (day-month-year, etc.
And my preference for awk is one of those 'you use the tools you know' moments.
4. What I wrote above will alomost certainly fail without some additional care
to make certain that the braces ({}) are passed properly by tex to the shell.
Bob Bruner
------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/
More information about the MacOSX-TeX
mailing list