Computing.Net > Forums > Unix > Renaming multiple files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Renaming multiple files

Reply to Message Icon

Name: b@bs
Date: July 17, 2003 at 12:07:27 Pacific
OS: Unix
CPU/Ram: 900/256
Comment:

anybody plz tell how to rename files like this using script

myfile.01 to yourfile.01
myfile.02 to yourfile.02
myfile.03 to yourfile.03
myfile.04 to yourfile.04
myfile.05 to yourfile.05



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: July 17, 2003 at 14:09:58 Pacific
Reply:

for file in \
myfile.01 \
myfile.02 \
myfile.03 \
myfile.04 \
myfile.05 ; do
mv $file yourfile`echo $file | cut -f2 -d '.'`
done



0

Response Number 2
Name: Don Arnett
Date: July 17, 2003 at 15:35:01 Pacific
Reply:

I've seen enough of David's answers to not question his scripting ability, so I assume that he's just answering the exact question asked.

If I assume that you want to rename all of the files who's names are myfile.*, you could use:


for file in myfile.*
do
mv $file yourfile`echo $file | cut -f2 -d '.'`
done

OR

for file in myfile.??


OR


for file in myfile.[0-9][0-9]


We've reached the limits of my regex ability!

This would save typing all of the filenames (I'm lazy)


0

Response Number 3
Name: b@bs
Date: July 17, 2003 at 15:47:58 Pacific
Reply:

tnx for the help

i've got lot of files starting with myfile.01 to myfile.99
is there any way to convert from myfile.* to yourfile.*



0

Response Number 4
Name: WilliamRobertson
Date: July 17, 2003 at 15:59:16 Pacific
Reply:

Change ext:

for f in myfile.+([0-9])*
do
print mv $f ${f%*.}.new
done


Change all but ext:

for f in myfile.+([0-9])*
do
print mv $f newfile.${f##*.}
done



0

Response Number 5
Name: WilliamRobertson
Date: July 17, 2003 at 16:03:40 Pacific
Reply:

...forgot to mention, that's ksh syntax. Doesn't seem to work in bash, zsh etc.


0

Related Posts

See More



Response Number 6
Name: b@bs
Date: July 17, 2003 at 17:06:45 Pacific
Reply:

thankx Don, David and William for the help.
gr8, the script working fine

thankx a lot.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Renaming multiple files

renaming multiple files www.computing.net/answers/unix/renaming-multiple-files/1651.html

gzip multiple files into one www.computing.net/answers/unix/gzip-multiple-files-into-one/7121.html

Check Multiple File Exists www.computing.net/answers/unix/check-multiple-file-exists/4775.html