Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
help! i need to automatically create a filename based on the prior date. variable='date +%Y%m%d' provides me with the format i need but for the current date. how do i substract one day from this number automatic... e.g. today is 12 Nov 2001, i need to name yesterday's date 20011111.data
greg

D'oh, wasn't thinking.... this won't work if it's the 1st of the month, obviously... that's quite a tricky one, although I'm sure it can be done with a perl one-liner with the date variable.... not too up on that myself though... sorry!

I'm bored so tried something... all I can come up with is this:
#!/usr/bin/perl
$ystrdy = time() ( 24 * 60 * 60 );
$thattime = (localtime $ystrdy);
print "$thattime\n";However this doesn't give you the numerical format that you want.. it'll give you something like Mon Nov 26 05:45:59 2001
You can use cut, paste etc to transpose this though... (and assuming you have perl on your machine). And if you had it in a script you could have
sed 's/Jan/01/g'
sed 's/Feb/02/g' ..... etc etcanyhow.
Hope this helps in some way. Sorry I can't be of any more help.

Okay you're probably fed up with me now, but just tried this... maybe it will satisfy your requirements. I saved the perl script to a file called testpl.
You can get a filename (in csh - my shell of choice) with
set myfile = `./testpl | sed 's/ //g' | cut -c 4-8,17-`
This runs the perl script to get yesterday's date, the sed command gets rid of the spaces, and the cut command picks out the info you want (Month, Day, Year).
(if this doesn't work quite right, try messing with the cust parameters as I had to do this on a Linux box at work - no perl on the sun box at my desk - doh!)
use the myfile variable however you need to.
Hope this helps, and I'll shut my big trap now! I was just bored on night shift!
Mark

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |