Ubuntu – How to rename the set of files with pattern


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.

Best Answer


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.

Related Question