Reputation: 712
I have hundred of id file with format like this
106527-Sup, Perman .jpg
106528-Iron, man .jpg
106529-Bat, man .jpg
106530-Spider, man .jpg
I need to rename them to
106527.jpg
106528.jpg
106529.jpg
106530.jpg
How do I it with regex and rename command
Upvotes: 0
Views: 90
Reputation: 95998
You can use perl-based rename
:
rename 's/^(\d+).*jpg$/$1\.jpg/' *.jpg
^
matches the position at the beginning of the input\d+
matches one or more digit.*
matches everything in between$
matches the position at the end of the inputThe first group ($1
) contains the digits you want to replace with.
Upvotes: 2