I have 100 folders with the first delimiter has a unique name i.e (123_hello and 575_hello) and each folder have atlist 1000 plus files with naming convention i.e (575_hello_1.iso ... 575_hello_1000.iso).
#!/bin/ksh
typeset -A ARR_ID
while read old_id new_id
do
ARR_ID[${old_id}]=${new_id}
done < pattern.txt
for dir in 123_hello 575_hello
do
d_id="${dir%%_*}"
if [ ! -z "${ARR_ID[$d_id]}" ]
then
for file in ${dir}/*.iso
do
fname="${file##*/}"
print "Renaming ${file} to ${dir}/${ARR_ID[$d_id]}_${fname#*_}"
#mv "${file}" "${dir}/${ARR_ID[$d_id]}_${fname#*_}"
done
fi
done
exit 0
Run it with mv commented, verify if you are getting desired output.
when I run your script I got error message:
./test1.sh: line 4: unexpected EOF while looking for matching `"'
./test1.sh: line 8: syntax error: unexpected end of file
Please, remember that the ultimate goal is for you to learn how to make that change that you are asking Yoda to do for you. Instead, you could ask: Is this the way I should change your code to not be specific to 2 folders? Then, you post what you have tried!
Yes, sorry for the typo. Do as Aia said, replace old_id] with old_id} .
And, I fully second Aia saying that you need to put in some - if not serious - efforts to master problems by yourself, not just copy-and-paste ready-made solutions.