Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question

closed as not constructive by John Gardeniers, ewwhite, Tom O'Connor, Ward, Zoredache Oct 11 '12 at 18:32

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

The shell tag tells us nothing. What operating system. Are those files all in the same directory? What scripting language do you want this in? What have you tried so far? – John Gardeniers Oct 11 '12 at 8:38
Thanks John for your suggestions, I have edited my question to improve it. – psaima Oct 11 '12 at 8:56

This should work as it's fairly standard bash

while read line
        set -- $line
        echo renaming "$1.txt to $2".txt
        mv "$1".txt "$2.txt"

    done <input.file
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.