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

Renaming files with *.let.* extension?

Status
Not open for further replies.

evild

Technical User
Nov 25, 2002
71
GB
I need to create a file rename script to run at a particular time. Part of the script must rename all files in the current directory that have *.let.* extension.

For example I may have
letter1.let.rdr
form3.let.bib
sqloutput.let.tlc

and I want to rename them to:

z_letter1.let.mon
z_form3.let.mon
z_sqloutput.let.mon

where 'mon' is an abreivieation on the day of the week. I already know how to get this variable and its defined as $dayofweek.

Is it possible to do a mv, that specifies all files of pattern *.let.* and saves them as *.let.$dayofweek in a different directory?



 
something to start with:

#!/bin/ksh

d=$(date +%a)

for i in *.let.*
do
echo "old->[${i}] new->[z_${i%%.*}.${d}]"
done


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks fo rthe tip but i need futher help with my c shell:


I have the following:
Code:
# Move and Rename all unprocessed *.let.* files
# in ccc50/print to Today's save directory
# Rename to z_u_*.dayofweek
cd $tm
foreach file (*.let.*)
mv $file &quot;/aleph/u52_5/alephe/renametesting/save/zu_$file.$dayofweek&quot;                                                                                         
end

If I run this and have something like c_r_001.let.rdr it renames it to zu_c_r_001.let.rdr.Thu
I would like to rename the files to something a little smaller say zu_c_r_001.Thu. How can I do this?

 
Have you tried the posted KSH tip?

Sorry, I don't do csh......

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I have figured out how to do it: by using two ':r' command to strip the filename to the desired effect.
 
I have another problem now...

i have the renames working fine now but i am having problems with the error messages produced by the script.

if i run:

Code:
# Move all *.rpt files in ccc50/print to Today's save directory
# Rename all *.rpt files in Todays save directory
cd $tm
foreach file (`ls *.rpt`)
mv $file &quot;$the_dir/z_$file.$dayofweek&quot;
end

# Move and Rename all unprocessed *.let.* files
# in ccc50/print to Today's save directory
# Rename to z_u_*.dayofweek
cd $tm
foreach file (`ls *.let.*`)
set filename = $file
set filename2 = $filename:r
set base = $filename2:r
mv $file &quot;$the_dir/zu_$base.$dayofweek&quot;
end

irt works fine. if there are no *.rpt files it returns 'no match' and continues the program. if there are no let files it returns 'no match'.
is it possible to supress this output? - i want nothin to appear on the command line.
 
ls *.let.* 2> /dev/null

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top