I will describe the problem quite verbose, as I have learned that only talking about a specific sub-problem I have identified leads to missed oppurtunities ... So I will put a tl;dr up front: There is a set of folders that need to be renamed according to a mapping in a CSV file.
The folder names follow the following pattern:
The digits in the middle are relevant and specify the new name the folder should have. So I could run the following sed command to extract the part of the foldername I am interested in.
So we might have a folder thats named
deptA100257_2bfde391c6af30fde3fca94b07bc8e7c and can pull out the relevant ID
100257. I then need to rename the folder according to the following CSV:
The new name is on the left, the ID of the old name on the right. So the folder from the example above should be renamed to
First obvious problem: Multiple Ids may map to a single name. I would solve this by creating all "new" folders up front and copy the folder contents instead.
And I could hack this up using Python or whatever, possibly even some bash loops. But something tells me that at the core, this operation (substitution according to a file) isn't exactly uncommon. So before re-inventing the wheel ...
I prefer solutions using standard *NIX shells and tools (especially bash or zsh) and no "external" languages like Perl, Ruby, Python ... But in the end I am more or less looking for a "smart" approach and if there is a nice Ruby one-liner that gets the job done, I am ok with that.