The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 11-15-2002
Vishnu Vishnu is offline
Registered User
  
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
replace those "rtf" and "doc" with $1 and $2 in your script...

I should add that the above way using "cut" will not work if you have multiple dots in your filename...

Code:
#!/bin/sh 
for name in `ls *.$1` 
do 
name1=`echo $name | sed -e "s/^\(.*\)\.$1$/\1\.$2/g"` 
mv $name $name1 
done
or a more compact and faster version which I prefer...

Code:
#!/bin/sh 
ls *.$1 | sed -e "s/^\(.*\)\.$1$/\1\.$1 \1\.$2/g" | xargs -n 2 mv -f
Cheers!
Vishnu.