rename multiple files with unique name
Posted
by
psaima
on Server Fault
See other posts from Server Fault
or by psaima
Published on 2012-10-11T08:22:09Z
Indexed on
2012/10/11
9:40 UTC
Read the original article
Hit count: 201
I have a tab-delimited list of hundreds of names in the following format
old_name new_name
apple orange
yellow blue
All of my files have unique names and end with *.txt extension and these are in the same directory. I want to write a script that will rename the files by reading my list. So apple.txt should be renamed as orange.txt. I have searched around but I couldn't find a quick way to do this.I can change one file at a time with 'rename' or using perl "perl -p -i -e ’s///g’ *.txt", and few files with sed, but I don't know how I can use my list as input and write a shell script to make the changes for all files in a directory. I don't want to write hundreds of rename command for all files in a shell script. Any suggestions will be most welcome!
© Server Fault or respective owner