i want to copy a filea.dat to a file name in the format
of filea_yyyymmdd_hhmi.dat
using something like DTSTAMP=$(date "+%Y%m%d"),
which puts it in format filea_yyyymmdd.dat
i want to copy a filea.dat to a file name in the format
of filea_yyyymmdd_hhmi.dat
using something like DTSTAMP=$(date "+%Y%m%d"),
which puts it in format filea_yyyymmdd.dat
#!/bin/ksh
# function for renaming
rename()
{
DTSTAMP=$(date "+%Y%m%d")
filename=basename($1)
file=${filename%.dat}
mv $filename $file"$DTSTAMP".dat
}
Looks like you already have it.
DATE=$(date +%Y%m%d)
TIME=$(date +%T)
cp filea.dat filea_$DATE.dat
or
cp filea.dat filea_$DATE_$TIME.dat
Hope this helps.
-x96
no that did not work. only the HHMM appeared in the file name,
I used
DTSTAMP=$(date "+%Y%m%d")
HMSTAMP=$(date "+%H%M")
cp /fdb/prod/fdbadm/data/nassst115d01.txt /fdb/prod/fdbadm/data/nass/FacilityMaster_$DTSTAMP_$HMSTAMP.dat
file name came out to be FacilityMaster_0732.dat - time only
i then reversed the order and had the time before the date, and then only the date appeared, but not the time.
DTSTAMP=$(date "+%Y%m%d")
HMSTAMP=$(date "+%H%M")
cp /fdb/prod/fdbadm/data/nassst115d01.txt /fdb/prod/fdbadm/data/nass/FacilityMaster_$HMSTAMP_$DTSTAMP.dat
file name became FacilityMaster_20070129.dat
Use braces around the variable names
cp /fdb/prod/fdbadm/data/nassst115d01.txt /fdb/prod/fdbadm/data/nass/FacilityMaster_${HMSTAMP}_${DTSTAMP}.dat
Use braces around the variable names worked perfectly.