Renaming files using list

filesrename

I have files available in a directory as:

filename15_1
filename15_2
filename15_3
filename15_4

And so on.

I have another file that contains mapping information for how I want to rename the files. This is a CSV file.

filename15_1,filename30_6
filename15_2,filename30_7
filename15_3,filename60_3
filename15_4,filename60_4
filename15_5,filename60_5
filename15_6,filename60_6

I want to rename the four files by reading the above mapping. Mapping files is having more information than the actual files present in the directory.

My files should be renamed to the following.

filename30_6
filename30_7
filename60_3
filename60_4

How can I do this?

Note: I am a database-background person and have little knowledge in Unix.

Best Answer

If your mapping file is comma separated, you can do this:

while IFS=, read orig target; do
    mv "$orig" "$target"
done < mapping.txt
Related Question