0

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.

0

2 Answers 2

2

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
1
  • @GillesQuenot, look again and you will see that $1 doesn't figure in the question. Mar 17, 2018 at 18:35

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