Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot, bind-address mysql multiple, sanibleone xxxx, ftp://192.168.100.100/, www.xxxcon

Links

XODOX
Impressum

#1: Adding

Posted on 2011-10-17 20:46:06 by 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
<http://cspl.me>


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#2: Re: Adding

Posted on 2011-10-17 20:55:30 by Leo Susanto

s/.+(\d{3}).jpg/Gyermekolimpia_Ujvidek_$1.jpg/i

On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal <csanyipal@gmail.com> 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
> <http://cspl.me>
>
>
> --
> 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/

Report this message

#3: Re: Adding /.JPG$//.jpg/ to a perlregexp

Posted on 2011-10-17 21:07:50 by Csanyi Pal

Leo Susanto <leosusanto@gmail.com> writes:

> On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal <csanyipal@gmail.com> 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
<http://cspl.me>


--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#4: Re: Adding /.JPG$//.jpg/ to a perlregexp

Posted on 2011-10-17 21:18:36 by 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 <csanyipal@gmail.com> wrote:
> Leo Susanto <leosusanto@gmail.com> writes:
>
>> On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal <csanyipal@gmail.com> 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/

Report this message

#5: Re: Adding /.JPG$//.jpg/ to a perlregexp

Posted on 2011-10-17 21:26:46 by Rob Coops

--20cf303bf792a1274c04af83978a
Content-Type: text/plain; charset=UTF-8

On Mon, Oct 17, 2011 at 9:07 PM, Csanyi Pal <csanyipal@gmail.com> wrote:

> Leo Susanto <leosusanto@gmail.com> writes:
>
> > On Mon, Oct 17, 2011 at 11:46 AM, Csanyi Pal <csanyipal@gmail.com>
> 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
> <http://cspl.me>
>
>
> --
> 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--

Report this message