Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date in output filename 1

Status
Not open for further replies.

moria6

MIS
Jul 11, 2000
30
0
0
US
Would like some help in inserting the date in the filename output from a perl program as such:

something.pl >> cfg072105.txt
something1.pl >> sam072105.txt

etc....

so output to a 3-letter desgination + mmddyy + .txt

Thanks in advance!


maurie
 
use backticks (not single speechmarks)

Code:
print `date "+%d%m%y"`;


Kind Regards
Duncan
 
Thanks, Duncan!

This worked for me:

#!/bin/bash
DATE=`date +'%m%d%y'`

something.pl >> cfg${DATE}.txt
something1.pl >> sam${DATE}.txt
.
.
.


Thanks again!


maurie
 
Yeah, [tt]MMDDYY[/tt] or [tt]DDMMYY[/tt] gives screwy sort orders in directory listings. I always use [tt]YYYYMMDD[/tt] and files automagically list chronologically. Makes it very easy to find oldest and newest files.
Code:
DATESTAMP=$(date '+%Y%m%d')
TIMESTAMP=$(date '+%H%M%S')

something1.sh >> cfg.${DATESTAMP}.txt
something2.sh >> sam.${DATESTAMP}.${TIMESTAMP}.txt
[ignore]</rant>[/ignore]

Hope this helps.
 
Thanks for the tip, Sam! Starting out there aren't so many files and I wouldn't have had a problem but after a while I'd have a huge directory to sort / search thru and THAT would have been painful.

Thanks again!


maurie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top