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

Script that searches file on date

Status
Not open for further replies.

Mickelkpg

IS-IT--Management
Oct 15, 2001
34
SE
I need to create a script that copy's a file that has the date in its filename, ex. ML-20011207.dat.
The file is located in the filestructure as follows:
/test/example/12 where 12 is the month.(there are 12 maps, one for each month.)
The file should be copied to /test/ididit/07 where 07 is the date of the day.(1-31 exists)
Then should it be renamed to ml1207.dat.

Can anyone help me?

Mind regard// Micke
 
Something like:

cp /test/example/`date +%m`/ML-20011207.dat /test/ididit/`date +%d`/ml`date +%m%d`.dat (all on one line of course)

might suffice, but be aware that this relies on the command being run on the same day as the original file's creation. Does this help?
 
Sorry - you can make ML-20011207.dat ML-`date +%Y%m%d`.dat if you wish too.
 
I'll make an assumption here Micke ...

- Filename is always of the format XX-yyyymmdd.dat

Lets say you have a shell variable FILENAME holding the filename (FILENAME=ML-20011207.dat). Then you could do

DOM=$(echo $FILENAME | cut -c10-11)
NEWFILE=ml$(echo $FILENAME | cut -v 8-11).dat
cp /test/example/12/$FILENAME /test/ididit/$DOM/$NEWFILE

Is this the sort of thing you're after?

Greg.
 
Thank You Ken, that was exactly what I was looking for.
Kind regards // Micke
 
I have a problem regarding this.
I have to copy/rename the file at 8:00 PM the day before the
files date.

Ex. This evening (2001-12-10) I want to copy/rename ML-20011211.dat.

Can You in some way use the date-command in a script like this but add i day (+1)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top