Results 1 to 7 of 7
Hello,
I would like to rename several files like
"recto 041.jpg" to "recto1 041.jpg"
"recto 042.jpg" to "recto1 042.jpg"
"recto 043.jpg" to "recto1 042.jpg"
I know the rename command
but ...
- 03-19-2010 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 6
[SOLVED] Rename multiples files (using rename and regexp)
Hello,
I would like to rename several files like
"recto 041.jpg" to "recto1 041.jpg"
"recto 042.jpg" to "recto1 042.jpg"
"recto 043.jpg" to "recto1 042.jpg"
I know the rename command
but I'm not very good about regular expressions...
I 've try something like
rename 's/^recto ???.jpg$/recto1 ???.jpg' *.jpg
but it doesn't work...
What is the good command for this
Kind regards
- 03-19-2010 #2
You actually just need a fairly simple regular expression here. All that you want to do is change the "recto" to "recto1", correct? Therefore, the following will work:
It's that simpleCode:rename 's/recto/recto1/' *.jpg
.
DISTRO=Arch
Registered Linux User #388732
- 03-19-2010 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 6
That's right it works fine with my examples
but the problem with your pattern is that
it can also match for name like
recto 041 recto.jpg
that will be converted to
recto1 041 recto1.jpg
instead of
recto1 041 recto.jpg
(In fact, I ask this in order to increase my knowledges about regexp)
- 03-19-2010 #4
Okay. So to be more specific, you only want to change "recto" if it's at the very beginning of the filename?
The '^' in the regular expression means "beginning of the string". Therefore, it will only match "recto" if it occurs at the very beginning.Code:rename 's/^recto/recto1/'
DISTRO=Arch
Registered Linux User #388732
- 03-19-2010 #5Just Joined!
- Join Date
- Aug 2008
- Posts
- 6
Thanks I know "^"
but how could I say
begin with "recto"
follow with a space
and containing 3 numbers
and ".jpg"
I think that it is something like :
^recto\ [0-9]{3}.jpg$
but I don't know what I should say to "rename" to
change this "recto" to "recto1"
- 03-19-2010 #6
Alrighty. I didn't realize that you wanted such a specific pattern
.
This uses the Perl-specific \d (which means [0-9]), and "captures" the group "\d{3}.jpg". In the replacement, it then says "recto1", followed by a space, followed by the first captured group.Code:rename 's/^recto (\d{3}.jpg)$/recto1 $1/' *.jpg
Does this all make sense?DISTRO=Arch
Registered Linux User #388732
- 03-19-2010 #7Just Joined!
- Join Date
- Aug 2008
- Posts
- 6
All right ! it is exactly what I was looking for !
I didn't know the \d
Thanks a lot !


