I was wondering whether it is possible to reuse whatever was matched in a path with globbing? (Just as it can usually be done with regex substitutions?)
I'm aware that there are other solutions for the following example, but I'm just using it as an example for what I'm asking:
Let's say have the files file_1.txt, file_2.txt, ..., file_100.txt
in the current folder, and I'd like to rename them to asdf_1_qwer.txt
, asdf_2_qwer.txt, ..., asdf_100_qwer.txt
. Of course I could match them with file_*.txt
, but can I somehow reuse whatever was matched in *
for specifiying the target file name?
rename
:rename -n 's/.*(\d+).*/asdf_${1}_qwer.txt/' ./file_[0-9]*.txt
– Gilles Quénot Sep 20 '23 at 13:07