Adding
am 17.10.2011 20:46:06 von Csanyi Pal
Hi,
my goal is to get in a directory the following:
PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_001.jpg
PIC00002.JPG renamed as Gyermekolimpia_Ujvidek_002.jpg
...
PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.jpg
So far I get this to work:
rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_110.JPG
etc.
PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.JPG
This is good but I want to make the .JPG extensions lowercase.
I know that the following command do this:
rename -v 's/\.JPG$/\.jpg/' *.JPG
but I want to know how to add
\.JPG$/\.jpg/
into the following command?
rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
--
Regards, Pal
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Adding
am 17.10.2011 20:55:30 von Leo Susanto
s/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i
On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal wrote:
> Hi,
>
> my goal is to get in a directory the following:
>
> PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_001.jpg
> PIC00002.JPG renamed as Gyermekolimpia_Ujvidek_002.jpg
> =A0...
> PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.jpg
>
>
> So far I get this to work:
>
> rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
> PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_110.JPG
> =A0etc.
> PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.JPG
>
> This is good but I want to make the .JPG extensions lowercase.
>
> I know that the following command do this:
> rename -v 's/\.JPG$/\.jpg/' *.JPG
>
> but I want to know how to add
> \.JPG$/\.jpg/
>
> into the following command?
> rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
>
> --
> Regards, Pal
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Adding /.JPG$//.jpg/ to a perlregexp
am 17.10.2011 21:07:50 von Csanyi Pal
Leo Susanto writes:
> On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal wrot=
e:
>> my goal is to get in a directory the following:
>>
>> PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_001.jpg
>> PIC00002.JPG renamed as Gyermekolimpia_Ujvidek_002.jpg
>> Â ...
>> PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.jpg
>>
>>
>> So far I get this to work:
>>
>> rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
>> PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_110.JPG
>> Â etc.
>> PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.JPG
>>
>> This is good but I want to make the .JPG extensions lowercase.
>>
>> I know that the following command do this:
>> rename -v 's/\.JPG$/\.jpg/' *.JPG
>>
>> but I want to know how to add
>> \.JPG$/\.jpg/
>>
>> into the following command?
>> rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
> s/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i
rename -v 's/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i' *.JPG
It works perfectly. Can you explain to me how does it works?
--=20
Regards, Pal
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Adding /.JPG$//.jpg/ to a perlregexp
am 17.10.2011 21:18:36 von Leo Susanto
http://perldoc.perl.org/perlre.html
s/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i
From your requirement: PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_001.jpg
1. the 3 last digits should be extracted: .+(\d{3}).jpg
2. rename everything before the 3 digits to:
'Gyermekolimpia_Ujvidek_':
s/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/
3. rename 'jpg' regardless of the combination of capitalization to
simple 'jpg': s/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i
On Mon, Oct 17, 2011 at 12:07 PM, Csanyi Pal wrote:
> Leo Susanto writes:
>
>> On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal wrote:
>>> my goal is to get in a directory the following:
>
> rename -v 's/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i' *.JPG
>
> It works perfectly. Can you explain to me how does it works?
>
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Adding /.JPG$//.jpg/ to a perlregexp
am 17.10.2011 21:26:46 von Rob Coops
--20cf303bf792a1274c04af83978a
Content-Type: text/plain; charset=UTF-8
On Mon, Oct 17, 2011 at 9:07 PM, Csanyi Pal wrote:
> Leo Susanto writes:
>
> > On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal
> wrote:
> >> my goal is to get in a directory the following:
> >>
> >> PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_001.jpg
> >> PIC00002.JPG renamed as Gyermekolimpia_Ujvidek_002.jpg
> >> ...
> >> PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.jpg
> >>
> >>
> >> So far I get this to work:
> >>
> >> rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
> >> PIC00001.JPG renamed as Gyermekolimpia_Ujvidek_110.JPG
> >> etc.
> >> PIC00223.JPG renamed as Gyermekolimpia_Ujvidek_223.JPG
> >>
> >> This is good but I want to make the .JPG extensions lowercase.
> >>
> >> I know that the following command do this:
> >> rename -v 's/\.JPG$/\.jpg/' *.JPG
> >>
> >> but I want to know how to add
> >> \.JPG$/\.jpg/
> >>
> >> into the following command?
> >> rename -n 's/\w\w\w\w\w/sprintf("Gyermekolimpia_Ujvidek_")/e' *.JPG
>
> > s/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i
>
> rename -v 's/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i' *.JPG
>
> It works perfectly. Can you explain to me how does it works?
>
> --
> Regards, Pal
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
I'll try :-)
Lets split it in the various parts first:
..+
(\d{3})
.. (this is not completely correct but we will get to that)
jpg
The first part basically tells the regular expression engine to find '.'
(any character) and to find it as often as it can +
The second step finds \d (a digit) exactly 3 times {3} and it is in brackets
which means these digits are captured for reuse later (we will get to that
as well). Thanks to the fact that this capture group is here the above .+
will not simply capture all characters but will stop due to the fact that
this bit matches the 3 digits in the file name.
The third bit where I said it is wrong is the . which captures any one
character after the 3 digits, it should probably have read \. which
restricts it to the . alone.
Then the last bit is no more then the extension preventing this from
matching some_file123.txt etc...
The next part is where we deal with the replacing of the previous file name
with the new one.
The first bit is no more then the new file name: Gyermekolimpia_Ujvidek_
Then the $1 which stands for the first capture group or (\d{3}) in our case
is placed here
The last bit places the extension there as .jpg
Then the one trick in all of this is the i at the end of the regular
expression which tells it to work in a case insensitive mode, so the capture
portion of your substitution that finds all files that match will find all
files where the last 3 charters are jpg regardless of how these are written.
So jpg or JPG or any other combination like JpG will be found providing that
the regular expression engine gets this far, it will stop trying to match as
soon as any of the elements above fails.
Regards,
Rob
--20cf303bf792a1274c04af83978a--