[SWLUG] timestamp in bash script
Dafydd Walters
dafydd at walters.net
Thu Dec 19 18:31:30 UTC 2002
> what are all the zeros?
I'm not sure what the zeros immediately after the dot are (fractions of a
second, perhaps ... to 9 decimal places !!!??)
The zeros after the plus sign represent your timezone (the difference
between your local time and GMT). The first two digits are hours, and the
second two are minutes.
> can i have colons in filenames
That is allowed, but colon is also the path separator.
> would gawk be the best thing in a small
> script to parse the above to get just the date and time
I tend to use sed for this kind of thing. For example, to populate a
variable MYVAR with the modification date and time up to and including
seconds, and substituting dots for the colons, of a file whose name is
stored in the variable FNAME, something like this should work:
MYVAR=`stat -c "%y" ${FNAME} | sed -e "s/\(.*\)\
\(.*\):\(.*\):\(.*\)\..*/\1_\2.\3.\4/"`
More information about the Swlug
mailing list