Link to home
Start Free TrialLog in
Avatar of mohona
mohona

asked on

Shell script for renaming files

Dear experts,

Please help me creating a bash/ksh shell script which will rename all .txt and .TXT files to .csv file in a particular directory and with in it's sub directories.

Thanks in advance.







SOLUTION
Avatar of wwnosal
wwnosal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of omarfarid
try

find /dir -name "*.txt' -o -name "*.TXT" | while read file
do
   nfile=`echo $file | sed 's/\....$//'`
   mv $file $nfile.csv
done
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ghostdog74
ghostdog74

if you  have Python, you can use the script here.
eg usage:


# ls -1
test.txt
test1.TXT
 
# filerenamer.py -p ".txt" -e ".csv" -l -I "tes*.*"
==>>>>  [ /home/test.txt ]==>[ /home/test.csv ]
==>>>>  [ /home/test1.TXT ]==>[ /home/test1.csv ]
 
# filerenamer.py -p ".txt" -e ".csv"  -I "tes*.*" #remove -l to commit
/home/test.txt  is renamed to  /home/test.csv
/home/test1.TXT  is renamed to  /home/test1.csv
 
# ls -1
test.csv
test1.csv

Open in new window

Avatar of mohona

ASKER

Thank you all.