Finding an empty field - take 2

Started by magarlick, July 06, 2022, 02:30:11 PM

Previous topic - Next topic

magarlick

I say 'Take 2' because this topic was dealt with in 2013 but when I tried to reply, it recommended I start a new thread.

So. I want to search a bunch of images to see if some fields are blank, e.g. Instructions/SpecialInstructions, and list those which are indeed blank. None of the answers given in the thread from 2013 works, so I assume the code has changed since then and the syntax needs modifying. I've tried this (as suggested in the 2013 thread):

exiftool -if 'defined $Instructions and $Instructions=~/(^\s*$)/' -filename DIR

No results returned even though I can see many that should match.

I also tried this

exiftool -if 'defined $Instructions and $Instructions=~/(^\s*$)/ or $SpecialInstructions and $SpecialInstructions' -filename DIR

and this

exiftool -if '$Instructions=~/(^\s*$)/' -filename DIR

Still no deal. I've tried the same syntax on other fields (Description/ImageDescription/Caption-Abstract and Keywords/Subject). Still no joy.

Advice from the experts, please!

With thanks. And I am running 12.42 on Linux Mint.

Phil Harvey

With ExifTool 12.42 I get this:

> exiftool a.jpg -instructions^=
    1 image files updated
> exiftool b.jpg -instructions=test
    1 image files updated
> exiftool a.jpg b.jpg -instructions
======== a.jpg
Instructions                    :
======== b.jpg
Instructions                    : test
    2 image files read
> exiftool a.jpg b.jpg -if 'defined $Instructions and $Instructions=~/(^\s*$)/' -filename
======== a.jpg
File Name                       : a.jpg
    1 files failed condition
    1 image files read


- 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 ($).

magarlick

Bizarre. I can replicate that.
> exiftool -overwrite_original test4.jpg -instructions^=
    1 image files updated
> exiftool -if 'defined $instructions and $instructions=~/(^\s*$)/' -filename  *
======== test4.jpg
File Name                       : test4.jpg
    8 files failed condition
    1 image files read

If I do exiftool -a -G1 -s test4.jpg, the list output shows that [XMP-photoshop] Instructions  is present but empty.

However, if instead of using "exiftool -overwrite_original test4.jpg -instructions^=", I go into Adobe Bridge and clear the instructions tag (Bridge is my main software for manipulating metadata), then I get this:
    9 files failed condition
    0 image files read


Now if I do exiftool -a -G1 -s test4.jpg, no tag named Instructions is present, which is why I guess the command fails.

The solution was to use this command:
exiftool -if 'not defined $instructions' -filename  DIR

Thanks. I got there in the end.

StarGeek

Yes, there's a difference between defined and 0 length or white spaces only, which is what the first command checks for, and if the tag doesn't exist in the first place.

To cover both, you could try this (haven't tested it though)
exiftool -if 'not defined $Instructions or $Instructions=~/(^\s*$)/' -filename DIR
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype