LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Changing multiple filenames with a script (https://www.linuxquestions.org/questions/linux-newbie-8/changing-multiple-filenames-with-a-script-140446/)

brecki 01-30-2004 01:58 PM

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

jazernorth 01-30-2004 02:17 PM

'man rename'

code:
---
rename .asm 40.asm *.asm
---

rename all files from .asm to 40.asm using mask of *.asm

homey 01-30-2004 02:21 PM

Try this...

for i in *.asm; do j=`echo $i | awk -F. '{print $1"40.asm"}'`; mv "$i "$j"; done

brecki 01-30-2004 02:24 PM

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.

jazernorth 01-30-2004 02:28 PM

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?

homey 01-30-2004 02:39 PM

Quote:

That won't work
Guess that means you aren't going to try it. ?

brecki 01-30-2004 02:40 PM

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

homey 01-30-2004 02:56 PM

Well the rename thing by jazernorth works also. Just that my script is more sexy looking. :)

jazernorth 01-30-2004 03:10 PM

My Motto is 'KISS':

Keep
It
Simple
Stupid


All times are GMT -5. The time now is 12:49 PM.