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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Issue

Status
Not open for further replies.

Roomer

Technical User
Oct 1, 2001
100
GB
Hi All,

I need to write a script that will allow me to change the following filenames....

In a directory each day I have numerous files named -

PXyymmdd.001
PXyymmdd.002

etc (approx 30 files)

The date within the filename is always yesterdays date...
I need a script that will change the date within the filename to today's date..

Any ideas / suggestions ?

Thanks for your time...
 
use date command to spit out string of format you like and assign to variable, for example:

readmanpages=$(date +%y%m%d)

then move file using variable substitution:

mv PXoldfile.001 PX${readmanpages}.001

IBM Certified -- AIX 4.3 Obfuscation
 
Hi

The script could be like that :

#--- Retrieve yesterday date from parameters
YestedayDate=$0

#--- Compute current date
TodayDate=`date +%Y%m%d`

for OldFile in `ls -1 PX${YesterdayDate}.*`
do
#--- Format new name
NewFile=`echo ${OldFile} | sed "s/${YestedayDate}/${TodayDate}/g"`

#--- Move file
mv ${OldFile] ${NewFile}
done
 
except $0 is the name of the script. you probably meant $1.

IBM Certified -- AIX 4.3 Obfuscation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top