Changing multiple filenames with a script
howdy,
I hava a directory that contains around 200 files with the following naming scheme: CCTP.asm, CCAS.asm, etc. I want to change all of those file names to CCTP40.asm, CCAS40.asm, etc. Basically, I want to add 40 to the end of each file name. How can I do this in a simple script? Thanks in advance |
'man rename'
code: --- rename .asm 40.asm *.asm --- rename all files from .asm to 40.asm using mask of *.asm |
Try this...
for i in *.asm; do j=`echo $i | awk -F. '{print $1"40.asm"}'`; mv "$i "$j"; done |
That won't work. You have to keep the original 4 characters of the name and the .asm extension. In other words, the file CCAW.asm needs to be changed to CCAW40.asm. This needs to be done in a for loop for over 200 files.
Therefore, I must seperate the CCAW part from the extension part of the filename and append 40 to CCAW and then append .asm to that. |
In order of commands:
--- [xxx@xxx xxx]$ ls *.asm CCAS.asm CCAW.asm CCTP.asm [xxx@xxx xxx]$ rename .asm 40.asm *.asm [xxx@xxx xxx]$ ls *.asm CCAS40.asm CCAW40.asm CCTP40.asm --- Isn't that the results you would like? |
Quote:
|
Homey,
Thanks a lot. Your script worked like a charm. for i in *.asm; do j=`echo $i | awk -F. '{print $1"40.asm"}'`; mv "$i "$j"; done |
Well the rename thing by jazernorth works also. Just that my script is more sexy looking. :)
|
My Motto is 'KISS':
Keep It Simple Stupid |
All times are GMT -5. The time now is 12:49 PM. |