The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: Renaming Files
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-19-2008
abch624 abch624 is offline
Registered User
 

Join Date: Feb 2008
Posts: 4
Renaming Files

Hi Alll,

I have a script that we use on the servers to change the name of files that have spaces in the name:

#!/bin/tcsh
set n = 0
foreach f ( * )
echo $f | grep " "
if ( $? == 0 ) then
mv "$f" `echo $f | sed -e "s/ /_/g"`
@ n += 1
endif
end
echo $n changed

I need to write a script which renames all ascii text files in the current directory by adding a number to their names before the “extension”. for example <name>_a<number>.<”extension”> for example creditA, creditB, creditC, debitA get changed to creditA1, creditB2, creditC3, debitA4. That is for changing all the files on the server to have a number in them......

I have this code which is wrong

#!/bin/tcsh
set n = 0
set m = 0
foreach f ( * )
file $f | grep "ascii text"
if ( $? == 0 ) then
mv "$f" `echo $f"_a"$m`
@ n += 1
@ m += 1
endif
end


I need to divide the $f into two parts one part before the . and the other part after the . but I dont know how. Any help

Any help...
Reply With Quote
Remove advertisements
!!
Forum Sponsor