Reputation: 18181
This is my bash code:
mv ./foo*foo2*foo3*.foo3 ./foo*.foo3
How can I refer to the second wildcard character from ./foo*foo2*foo3*.foo3
when renaming my file using the mv
command?
I'm sorry if this sounds stupid, but I couldn't find an answer anywhere. Maybe I'm using incorrect terminology? If so, please let me know.
Upvotes: 2
Views: 169
Reputation: 52000
The rename
tool is just for that:
sh$ touch fooAfoo2Bfoo3C.foo3
sh$ rename -v 's|foo.*foo2(.*)foo3.*\.foo3|foo$1.foo3|' *.foo3
# ^^^^ ^^
# capture the insert
# second "wildcard" ---> here
fooAfoo2Bfoo3C.foo3 renamed as fooB.foo3
Upvotes: 1
Reputation: 174706
Try the below rename command on the directory where the original file is located.
rename 's/^.*\./foo\*\./' *.foo3
It renames foo*foo2*foo3*.foo3
file to foo*.foo3
Upvotes: 1