-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, 7 Aug 2008, Walter Faleiro wrote:
> All,
> We have a script to cleanup filesystem.
> It contains the following lines in the code
>> #!/bin/bash
>> DAYSPERMONTH=("31" "29" "31" "30" "31" "30" "31" "31" "30" "31" "30" "31" )
> CDSTAMP=`date '+%Y%m%d'`
>> bash-3.00# date '+%Y%m%d'
> 20080807
>>> CURRENTYEAR=`echo $CDSTAMP | awk '{print substr($1,1,4)}'`
If you're using GAWK (almost guaranteed if its a Linux server, and
GAWK is easily available for most other platforms), the sub-command
and echo are quite redundant, instead:
gawk 'BEGIN {print strftime("%Y%m%d") }'
It should be obvious how you can make it print the various
sub-strings you want (man strftime).
In order to guarantee you manipulate only one date, you may wish to
operate on a fixed timestamp:
gawk 'BEGIN {ts = systime(); print strftime("%Y%m%d", ts) }'
regards,
- --
Paul Jakma paul at clubi.iepaul at jakma.org Key ID: 64A2FF6A
Fortune:
Weiner's Law of Libraries:
There are no answers, only cross references.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iHUEARECADUFAkicFjYuGmh0dHA6Ly93d3cuamFrbWEub3JnL35wYXVsL3BncF9w
b2xpY3ktMS4xLnR4dAAKCRDYa/eUZKL/arwHAKCpacgr5fyGDD9dSOGtMvJx+0g0
pgCdFg5xmEDks8RwfKVBf/KhBqNetq0=
=YQbx
-----END PGP SIGNATURE-----
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!