It may make more sense to move the digits to the end of the filename:
Code:
for file in *itdesc.txt; do number=$(echo "$file" | sed "s/^\([[:digit:]][[:digit:]]*\)\([[:alpha:]]*\)/\2\1/"); echo $number; done
itdesc01.txt
itdesc02.txt
itdesc03.txt
itdesc04.txt
itdesc05.txt
itdesc06.txt
itdesc07.txt
itdesc08.txt
itdesc09.txt
itdesc10.txt
itdesc11.txt
If this looks OK change
echo "${number}" to
"mv "${file}" "${number}".
Another option is to use
ls *itdesc* | cat -n to produce a list of matching filenames preceded by an ordinal number.
Code:
1 01itdesc.txt
2 02itdesc.txt
3 03itdesc.txt
4 04itdesc.txt
5 05itdesc.txt
6 07itdesc.txt
7 09itdesc.txt
8 10itdesc.txt
9 11itdesc.txt
10 12itdesc.txt
11 13itdesc.txt
Look at what characters are used to separate the fields:
ls *itdesc* | cat -n | od -c
Code:
0000000 1 \t 0 1 i t d e s c .
0000020 t x t \n 2 \t 0 2 i t d
0000040 e s c . t x t \n 3 \t 0
...
Note the use of spaces and tabs.
You may want to do this in steps to make it easier to test as you go along, and come up with a sed command the produces a rename script which you can run to perform the renaming. This makes it easier to develop the sed command.
Code:
ls *itdesc* | cat -n >temp
sed 's/^ *\([[:digit:]][[:digit:]]*\)\t\([[:digit:]][[:digit:]]\)\([[:alpha:]]*\)\.\([[:alpha:]]*\)/mv \2\3.\4 \3\1.\4/' temp >renamescript
chmod +x renamescript
rm temp
./renamescript
rm renamescript