I have a large number of files I want to rename. Each filename contains a number (xxx): FIXED_PART_xxx_UNIQUE_PART
.
I also have a text file, which has a number and a string in each line:
001 string001
002 string002
...
112 string112
there is an entry for each file, but not necessarily a file for each entry. I want to rename each file by parsing the xxx
part and replacing it with the string from the file.
What is the best way to do that?
edit: the actual file names look like this:
Berlin_Ost_034_some_variable_text.jpg
so the fixed part contains also an underscore in this case, but it is the same for each folder. The xxx part consists only of numbers.
the output would be for this file
Berlin_Ost_Sommer_some_variable_text.jpg
and I am talking about 200 files
The text file contains a line: 034 Sommer
which is why the 034 part in the file gets replaced by Sommer
The file contains all sorts of strings, but only characters and numbers and german umlauts. The first part is always a number. Here is a part from one of the files I am using
033 Winter
034 Sommer
035 Herbst
036 Frühling
037 Abends.kurz.vor.Sonnenaufgang
I am using linux
xxx
always be digits? Also, what operating system are you using? Different systems come with different tools.xxx
is the third underscore-delimited item in each filename? If not, what criteria can we use to identify and extract it? How many files is "a large number" - tens, hundreds, thousands, more? All in the same directory or spread across several directories?Sommer
come from? Presumably, there will be a line withSommer
in the text file, but since we cannot see it, that doesn't help. We need to see an actual example (or a few) because there are all sorts of details that can affect the solutions. And we really need to know what operating system you are using.