I don't have the original conversation, but I would assume rename is a script 
taking 2 arguments.  The first a regex to replace the title and the second the 
file list.  This would mean rename is the script to be executed, the regex is 
as I described before and the *.JPG would shell expand to any file whose name 
ends in '*.JPG'.
--
Paul Mooring
Systems Engineer and Customer Advocate

www.opscode.com

From: Michael Havens <bmi...@gmail.com<mailto:bmi...@gmail.com>>
Reply-To: Main discussion list 
<plug-discuss@lists.plug.phoenix.az.us<mailto:plug-discuss@lists.plug.phoenix.az.us>>
Date: Tuesday, September 11, 2012 10:47 AM
To: Main discussion list 
<plug-discuss@lists.plug.phoenix.az.us<mailto:plug-discuss@lists.plug.phoenix.az.us>>
Subject: Re: find and replace


So the full string I was given is:

   rename 's/\.JPG$/.jpg/' *.JPG

So what does the *.JPG do? If you 's(earch)/string/(replace)string' then what 
is the need for *JPG?
:-)~MIKE~(-:


On Tue, Sep 11, 2012 at 9:49 AM, Paul Mooring 
<p...@opscode.com<mailto:p...@opscode.com>> wrote:
When you do search and replace, the replace section is literal not a pattern 
match.  So piece by piece:
s/ # This means match the first section and replace with the second
\.JPG$/  # This means a literal '.' at any point in the string followed by 
'JPG' then the end of the line
.jpg/ # This is the string to replace the previous regex with '.jpg'
--
Paul Mooring
Systems Engineer and Customer Advocate

www.opscode.com<http://www.opscode.com>

From: Michael Havens <bmi...@gmail.com<mailto:bmi...@gmail.com>>
Reply-To: Main discussion list 
<plug-discuss@lists.plug.phoenix.az.us<mailto:plug-discuss@lists.plug.phoenix.az.us>>
Date: Tuesday, September 11, 2012 9:42 AM
To: Main discussion list 
<plug-discuss@lists.plug.phoenix.az.us<mailto:plug-discuss@lists.plug.phoenix.az.us>>
Subject: Re: find and replace

Hate to resurrect old stuff but in

   rename 's/\.JPG$/.jpg/' *.JPG

is this saying to s(earch)/(for the string).JPG$/(replace with).jpg/ ? Why does 
one not need the escape character (\) before the period here or before the 
final JPG? What does the *.JPG at the end signify?
:-)~MIKE~(-:


On Tue, Feb 21, 2012 at 7:32 AM, Sam Kreimeyer 
<skrei...@gmail.com<mailto:skrei...@gmail.com>> wrote:
Here's a pdf of a quick guide to regular expressions
http://www.addedbytes.com/download/regular-expressions-cheat-sheet-v1/pdf/

Basically, it's a format for defining search patterns that supports special 
meanings for certain characters. For instance:

a - finds any string like "a"
a. - finds any string like "a" plus any other character except a new line 
(matches "aa", "ab", "ac", etc)
a.* - finds any string like "a" plus zero or more characters except a new line 
(matches "aa", "abcdefghijk")
Other special characters can further modify this behavior.

So here's an explanation of the earlier command.

's/\.JPG$/.jpg/' *.JPG

Basic search and replace format s/[string we search for]/[string to replace 
matches with]/

"\.JPG$" - Because "." is special, we escape it with "\" to keep the regex from 
interpreting it, so the "." will be treated literally. "JPG" is what we're 
looking for. Placing a "$" at the end of the string tells the regex to match 
the string only at the end of the strings you're searching. This means that you 
will match "example.JPG" but not "JPG.example".

".jpg" - This is our replacement string. This is what goes in the place of 
every match we find.

"*.JPG" - while this isn't part of the regex, "*" is a wildcard (can be 
substituted for any number of characters).

Hope that helps!

---------------------------------------------------
PLUG-discuss mailing list - 
PLUG-discuss@lists.plug.phoenix.az.us<mailto:PLUG-discuss@lists.plug.phoenix.az.us>
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


---------------------------------------------------
PLUG-discuss mailing list - 
PLUG-discuss@lists.plug.phoenix.az.us<mailto:PLUG-discuss@lists.plug.phoenix.az.us>
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

Reply via email to