0

This question already has an answer here:

I've a set of files named in the following manner:

_9978967868768763ghjgj7598983678hjva_week1-6.pdf
_78637832bdsjh275637bkkaww786b_week12-32.pdf
8786767867868978713bkwkhjhkjqw_week1-622.pdf
867813567bdjsbgbadsyu6712353125561235_week100-6.pdf

I'm intersted in making use of rename utility to obtain names:

 week1-6.pdf
 week12-32.pdf
 week1-622.pdf
 week100-6.pdf

The regex to achieve that could be be:

(.*)(week.*)

which works fine (regex101):

enter image description here

Question

How do I translate this syntax into rename's expression of format:

s/expr1/expr2/[gi]

In effect, I want to delete first group.

Notes

I'm not interested in using mv or sed-based solution. I want to use rename utility only.

marked as duplicate by αғsнιη, elbarna, Jesse_b, G-Man Says 'Reinstate Monica', Wouter Verhelst Mar 18 '18 at 22:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Try this, using the proper way :) just correcting your command (you are very close...) :

rename 's/(.*)(week.*)/$2/' *.pdf

or to simplify :

rename 's/.*(week.*)/$1/' *.pdf
1

prename approach:

prename -n 's/.*_(week.*$)/$1/' *_week*.pdf
  • $1 - points to the 1st captured group
  • @GillesQuenot, look again and you will see that $1 doesn't figure in the question. – RomanPerekhrest Mar 17 '18 at 18:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.