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!

Change filename

Status
Not open for further replies.

swaroop

Programmer
Feb 4, 2001
100
US
#!/bin/ksh
for fl in $(find /home/txhylmr/cafe/ -name '*.C'); do
mv fl fl.cpp
done

This script doesnot work. It results in filenames as first.C.cpp second.C.cpp so on...
I need to see them as first.cpp second.cpp and so on....

Please help me.

Thanks in advance.

Swaroop.
 
Are you trying to change the file extension?

Try this, if you are:

#!/bin/ksh

old_ext=pl
new_ext=pm
for file in $(ls *.$old_ext)
do
mv $file ${file%${old_ext}}${new_ext}
done
 
Try this (in ksh):
Code:
for fl in $(find /home/txhylmr/cafe/ -name '*.C'); do
  mv $fl  ${fl%.C}.cpp
done


Hope This Help
PH.
 
Here is another way that might work for you. This one dosen't use a loop. (ksh & AIX 4.3)

[tt]ls -1 *.C|xargs -I{} basename {} .C|xargs -I{} mv {}.C {}.cpp[/tt]


JRjr[morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top