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!

Doing a rename using a wildcard? 2

Status
Not open for further replies.

jisoo23

Programmer
Jan 27, 2004
192
US
Hello everyone,

Ok so I'm a literal newbie to Unix scripting (kornshell in my case) so try not to flail me too much =D

I have a bunch of files that have this sort of format:

test1.log
test2.log
test3.log

I'm trying to create a script that will take those files and rename them with the current datestamp in the middle like so:

test1_102705.log
test2_102705.log
test3_102705.log

I tried the following command:

mv test?.log test?_`date '+%m%d%y'`.log

But my AIX box obviously didn't like that =P I'm sure this is probably a pretty simple thing but I haven't seen any similar examples around using a wildcard. Any help is appreciated!

Thanks,
Jisoo23
 
for f in test*.log; do mv $f ${f%.log}_$(date +%m%d%y).log; done


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Try this...
Code:
#!/bin/ksh

ls -1 test?.log | while read FILE
do
    mv ${FILE} ${FILE%.log}_$(date '+%m%d%y').log
done
Hope this helps.
 
Hey that was quick. Thanks guys, I'll try out both of them!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top