ExifTool Forum

ExifTool => Newbies => Topic started by: mblanchette on May 09, 2019, 11:49:52 AM

Title: Help with -if syntax
Post by: mblanchette on May 09, 2019, 11:49:52 AM
Hello,

I am trying to use exiftool to identify Pentax Pixel Shift images, but I have not been able to make it work.

I started by running:
exiftool -PixelShiftResolution -Quality -csv *.pef
, to make sure that I have files to process, but ran into trouble when I got to the -if logic.  I have tried all below, without success.  Can someone tell me what I am doing wrong?  Thanks!

exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution == 1" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution == On" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution eq On" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution eq 1" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution = 1" -csv *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution = On" -csv *.pef
exiftool -Name -if $PixelShiftResolution="On" -csv *
exiftool -Name -if $PixelShiftResolution="On" -csv .
exiftool -Name -if '$PixelShiftResolution = 1' -csv *
exiftool -Name -if '$PixelShiftResolution == 1' -csv *
exiftool -Name -if '$PixelShiftResolution' -csv *
exiftool -Name -if '$PixelShiftResolution eq "On"' -csv *
exiftool -Name -if '$PixelShiftResolution = "On"' -csv *
exiftool -Name -if '$PixelShiftResolution == "On"' -csv *
exiftool -Name -if '$PixelShiftResolution == 1' -csv *
exiftool -Name -if '$PixelShiftResolution = 1' -csv *
exiftool -Name -if '$PixelShiftResolution eq 1' -csv *
exiftool -Name -if '$Quality ge 7' -csv *
exiftool -Name -if "$Quality ge 7" -csv *
exiftool -Name -if "$Quality = 7" -csv *
eexiftool -PixelShiftResolution -Quality -if "$Quality eq 7" -csv *
Title: Re: Help with -if syntax
Post by: Phil Harvey on May 09, 2019, 12:00:15 PM
Wow, that's a lot of hit-n-miss.

Try this (the quoting assumes you are on Mac or Linux):

exiftool -PixelShiftResolution -Quality -if '$PixelShiftResolution eq "On"' -ext pef .

The 'eq' operator is used for string comparisons, and "On" must be quoted because it is a string.

- Phil
Title: Re: Help with -if syntax
Post by: StarGeek on May 09, 2019, 12:11:18 PM
Since I'm slow and had already typed all this out, here's some more details.

The PixelShiftResolution has a raw numeric value of 0 or 1, which exiftool will display (printConv) as a string of Off/On.  To do a string comparison, you would use eq to see if it is exactly equal (no substring search).  Also, as a string, what you are comparing to must be in quotes.  Case does matter in this comparison.  The type of quotes depends upon the system.  Phil shows the Mac/Linux version.  On Windows CMD, you need double quotes around the whole things and single quotes around the matching string (Powershell is different and I'm not sure exactly how to quote it there, possibly the same as Mac/Linux).  This should work under Windows:
-if "$PixelShiftResolution eq 'On' "

You can also compare the raw value.  In that case, you would add a hashtag to the end of the name, use the double equal sign ==, and wouldn't need to quote the value.
-if "$PixelShiftResolution# == 1"

Finally, you can use a regex match.  This allows for substring searches as well as case insensitive search option by adding a trailing i.
-if "$PixelShiftResolution =~/on/i"
Title: Re: Help with -if syntax
Post by: mblanchette on May 10, 2019, 07:08:53 AM
Thanks Phil.  I tried everything BUT putting doubles inside singles (Windows ).  This worked:

exiftool -Name -if "$PixelShiftResolution eq 'On'" .

Thanks again!