I have files which has name as following:


Here the value 50 and 8 needs renaming & The results should be something like:


I tired few similar to rename 's/\d{3}(\d{*})\.csv$P21_$1.csv' *.csv But no luck. (It seems I am really bad at Linux regex)

The value 50->21 and 8->3 is something that i know. But the starting value and ending value is not always in same digit size.


1 Answer 1



rename -n 's/50(_.*)_8/21$1_3/' *.csv

The -n flag doesn't do any renaming. You can test patterns this way. Remove it for actually performing the renaming.

  • 2
    Also provide info that : -n used for no-act and finally remove -n for apply.
    – Pandya
    Sep 14, 2014 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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