Script to change the extension in folders
Hi,
i want to write a script to change the extension of a file to new extension. i already wrote a script which i can change all the files in one folder, but the thing that i have more then 300 folders, and i want to go to each folder and run the script. is there a way, to run the script, so it can go to each folder and change the extension. for example, the main folder is "main" located in /root/home/main in main folder, i have the folders: f1, f2, f3, ..., f100. the files located in "f1, f2, ..." are like this: "1.txt;1", "2.tta;1", etc,, the extension is ".txt;1", "tta;1". so, my script is: Code:
#!/bin/bash Thanks in advance. regards |
Please be aware of
0) proper quoting, 1) the difference between "for" and "while" loops, 2) problems due to spaces in file names and 3) using the wrong tool for the right job (like using 'ls' instead of 'find'): Code:
find /root/home/main -type f -iname "*.txt;*" | while read ITEM; do Code:
function help() { echo "Bash scripting guides: |
I am surprised the original script worked at all as a semi colon is deemed the end of the previous command.
A slight edit you can do on unSpawn's script is: Code:
NEWNAME="${ITEM//;1/}" |
[QUOTE=unSpawn;4523007]Please be aware of
0) proper quoting, 1) the difference between "for" and "while" loops, 2) problems due to spaces in file names and 3) using the wrong tool for the right job (like using 'ls' instead of 'find'): Code:
find /root/home/main -type f -iname "*.txt;*" | while read ITEM; do Very big thanks for you, i really appreciate your help, it save me lot of time. and also thanks for the advise. Regards |
All times are GMT -5. The time now is 04:45 AM. |