Creating an -if condition in structured tags

Started by marcosBal, August 31, 2018, 02:55:30 PM

Previous topic - Next topic

marcosBal

I want to output a structured xml file using -X -struct.

I also want to create an -if EXPR condition so that only certain files are processed.

The EXPR in the condition includes a nested XMP tag. I know how to search a top-hierarchy tag using e.g. -if "$XMP:entries =~ /text/" , but I do not know how to search a tag within XMP:Entries. I have unsuccessfully tried several variations of -if "$XMP:entries/XMP:Entry =~ /text/" .
Any ideas??

Thanks

Marcos

Phil Harvey

Hi Marcos,

I don't know specifically what you want to do, but you can access a specific field in a structured tag through the flattened tag.  In your example, the flattened tag name could be XMP:entriesEntry.

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

marcosBal

Hi Phil,

That does not seem to work for me for this particular kind of file, which is a sidecar xml file (which happens to have extension .DBX). If I try

>exiftool -ext dbx -if "$XMP:entriesEntry =~ /textToSearch/" -X -struct dir/filename

exiftool tells me the file has failed the condition.

But if I write

>exiftool -ext dbx -if "$XMP:entries =~ /textToSearch/" -X -struct dir/filename

the output is correct: it has found the text in the larger path.

Could this be because the file I am searching is an xml file, not an image file? Again, the structure of the sidecar file is
<XMP:entries>
  </XMP:Entry>
     . . .
    textToSearch

Thanks!

Marcos

Phil Harvey

Hi Marcos,

If you use the -struct option then you won't see the flattened EntriesEntry tag.

Use this command to extract all information:

exiftool -s FILE

then use the tag name from this output in the -if condition.

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

marcosBal

Hi, Phil,

So -if conditions that specify nested fields are incompatible with the -struct option, right?

Thanks again!!

Marcos

Phil Harvey

If you request -struct tags, then your -if condition must operate on the structures too.

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

marcosBal

Hi, Phil,

That helped! Using -s -X -struct shows that the structure within XMP:entries is flattened, albeit using some {} and field names (almost as if they were attributes of <XMP:entries>) to imply structure.


XMP:entries='{Entry={. . .otherField=value, fieldToSearch=textToSearch, anotherField=value. . . }}'


So I just did the same search, but this time including the field within which I wanted to search as text:

-if "$XMP:entries =~ /fieldToSearch=textToSearch/" ,

and that works.

However, in this case it works because the text I am searching (textToSearch) is right at the beginning of fieldToSearch. Not sure how I would search text not at the beginning of fieldToSearch. Any ideas??

Thanks!!

Marcos

Phil Harvey

Hi Marcos,

You could do this: -if "$XMP:entries =~ /fieldToSearch=[^=]*textToSearch/"

Then there could be anything but an equals sign before the textToSearch.

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

marcosBal