Need help with an if statement

Started by Tarn, March 16, 2013, 08:04:53 PM

Previous topic - Next topic

Tarn

Hi Phil

What I am trying to do is find any file that is in the Adobe RGB color space that the original file name is incorrect.

I store the original file name, that the camera gives the file, in UserComment; and am searching on that tag.

The logic is: If Color space is "Adobe" RGB OR "Uncal"ibrated AND the first character in Usercomment is NOT "_" (an underscore) list the file name, and other info. In short, I want it to show the files that have an improper name stored in UserComment, and ignore the one that are properly named, or in the sRGB color space.

With that, below is a copy from the screen. As you can see there is a slight problem in that it keeps picking out a file that is properly named in UserComment and displaying it. Triple asterisks mark the file name that should not be in the list.


U:\Holding>et -filename -Usercomment -colorspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
101108-6641.NEF _DSC6641.NEF    Adobe RGB
P3138172.JPG    P3138172.JPG    sRGB
P3138172.orf    _3138172.ORF    sRGB
_3138171.jpg    P3138171.JPG    Uncalibrated
_3138171.ORF    _3138171.ORF    Uncalibrated

U:\Holding>Match

U:\Holding>et -if "${Colorspace;$_=substr($_,0,5)} eq 'Uncal' or ${Colorspace;$_=substr($_
,0,5)} eq 'Adobe' and ${UserComment;$_=substr($_,0,1)} ne '_'" -filename -Usercomment -col
orspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
_3138171.jpg    P3138171.JPG    Uncalibrated
_3138171.ORF    _3138171.ORF    Uncalibrated ***

U:\Holding>Match

U:\Holding>et -if "${Colorspace;$_=substr($_,0,5)} eq 'Adobe' or ${Colorspace;$_=substr($_
,0,5)} eq 'Uncal' and ${UserComment;$_=substr($_,0,1)} ne '_'" -filename -Usercomment -col
orspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
101108-6641.NEF _DSC6641.NEF    Adobe RGB ***
_3138171.jpg    P3138171.JPG    Uncalibrated

U:\Holding>Match

U:\Holding>et -if "${UserComment;$_=substr($_,0,1)} ne '_' and ${Colorspace;$_=substr($_,0
,5)} eq 'Uncal' or ${Colorspace;$_=substr($_,0,5)} eq 'Adobe'" -filename -Usercomment -colorspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
101108-6641.NEF _DSC6641.NEF    Adobe RGB ***
_3138171.jpg    P3138171.JPG    Uncalibrated

U:\Holding>Match

U:\Holding>et -if "${UserComment;$_=substr($_,0,1)} ne '_' and ${Colorspace;$_=substr($_,0
,5)} eq 'Adobe' or ${Colorspace;$_=substr($_,0,5)} eq 'Uncal'" -filename -Usercomment -col
orspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
_3138171.jpg    P3138171.JPG    Uncalibrated
_3138171.ORF    _3138171.ORF    Uncalibrated ***

U:\Holding>


In the first two checks the "and" clause was at the end. In the second two, I moved it to the beginning. In all four cases, it looks as if it is ignoring the first "if" clause. The one before the "or" statement.

If I use either of the clauses that check ColorSpace, with the "and" clause, that checks for something other than the "_" as the first character of UserComment, they work fine. It is when I try to join them with the "or" statement that it falls apart.

What am I messing up?

TIA

 


Phil Harvey

The operator precedence of the logical "and" and "or" is messing you up.  "and" is higher precedence than "or", so the order doesn't matter and the "and" is evaluated first.  You need brackets if you want a different order.

But you can simplify what you have done using (gasp) regular expressions:

et -if "$Colorspace =~ /^(Adobe|Uncal)/ and $UserComment !~ /^_/" -filename -Usercomment -col
orspace . -T


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Tarn

That's CHEATING!!! You know how to speak this language... I don't. :D

That works perfectly. Thanks.