LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-30-2004, 01:58 PM   #1
brecki
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Rep: Reputation: 0
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
 
Old 01-30-2004, 02:17 PM   #2
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Rep: Reputation: 15
'man rename'

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

rename all files from .asm to 40.asm using mask of *.asm
 
Old 01-30-2004, 02:21 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Try this...

for i in *.asm; do j=`echo $i | awk -F. '{print $1"40.asm"}'`; mv "$i "$j"; done
 
Old 01-30-2004, 02:24 PM   #4
brecki
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 01-30-2004, 02:28 PM   #5
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Rep: Reputation: 15
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?
 
Old 01-30-2004, 02:39 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Quote:
That won't work
Guess that means you aren't going to try it. ?
 
Old 01-30-2004, 02:40 PM   #7
brecki
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 01-30-2004, 02:56 PM   #8
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Thumbs up

Well the rename thing by jazernorth works also. Just that my script is more sexy looking.
 
Old 01-30-2004, 03:10 PM   #9
jazernorth
Member
 
Registered: Jan 2004
Location: Green Bay
Distribution: RedHat 8.0, LFS-5.0
Posts: 100

Rep: Reputation: 15
My Motto is 'KISS':

Keep
It
Simple
Stupid
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script to remove spaces from multiple filenames jeffreybluml Linux - Newbie 36 07-31-2013 02:10 AM
script to change multiple filenames in a directory jeffreybluml Linux - Newbie 8 12-06-2006 01:46 AM
need help with script to remove all metachars from filenames BrianK Programming 5 08-20-2005 11:10 PM
Script to run script in multiple directories... seabass55 Linux - General 5 07-06-2004 12:44 AM
bash shell script appends '?' to filenames sceptreofjudah Linux - Newbie 3 03-18-2004 08:54 AM


All times are GMT -5. The time now is 10:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration