ExifTool Forum

ExifTool => Newbies => Topic started by: ssmith001 on September 11, 2013, 11:22:05 AM

Title: Adding values to Subject
Post by: ssmith001 on September 11, 2013, 11:22:05 AM
I'm having a little trouble with the command syntax to add a value to a field. I am trying to figure out how to add a value, in this instance, the last 7 digits before the extension, to the Subject field, but ONLY if that value (2182451) doesn't already exist in the Subject field.

The filename is: 02700042234_2182451.eps

This is the command I'm using:

exiftool '-xmp:subject+<${filename;$_=substr($_,-11,7)}' -overwrite_original *.eps
Title: Re: Adding values to Subject
Post by: StarGeek on September 11, 2013, 03:50:37 PM
From the FAQ (https://exiftool.org/faq.html#Q17):
QuoteTo prevent duplication when adding new items, specific items can be deleted then added back again in the same command. For example, the following command adds the keywords "one" and "two", ensuring that they are not duplicated if they already existed in the keywords of an image:

So maybe try something like
exiftool '-xmp:subject-<${filename;$_=substr($_,-11,7)}' '-xmp:subject+<${filename;$_=substr($_,-11,7)}' -overwrite_original *.eps
Title: Re: Adding values to Subject
Post by: ssmith001 on September 11, 2013, 04:07:04 PM
Just tried that and ran it twice, which should in essence remove then add, then remove and add again, resulting in a single value, but it actually added the same value twice, as shown here:

Hunt's Hunt's Premium Pasta Sauce; Chunky Vegetable 26 Oz Grocery 26 Oz; 2182451; 2182451

Oddly enough, subsequent executions didn't result in additional values of 2182451 being added, just the 1st and 2nd executions.
Title: Re: Adding values to Subject
Post by: Phil Harvey on September 11, 2013, 07:14:03 PM
Subsequent executions should continue to add the value.

This one is a bit tricky.  From the -tagsFromFile documentation:

            5) The normal behaviour of copied tags differs subtly from that of
            assigned tags for list-type tags.  When copying to a list, each
            copied tag overrides any previous operations on the list.  While
            this avoids duplicate list items when copying groups of tags from
            a file containing redundant information, it also prevents values
            of different tags from being copied into the same list when this
            is the intent.  So a -addTagsFromFile option is provided which
            allows copying of multiple tags into the same list.  ie)

                exiftool -addtagsfromfile @ '-subject<make' '-subject<model' ...

            Other than this difference, the -tagsFromFile and -addTagsFromFile
            options are equivalent.

In your case, the 2nd argument overrides the first.  To prevent this, use -addTagsFromFile.

- Phil