transferring tags based on content

Started by neebah, September 28, 2016, 10:36:25 PM

Previous topic - Next topic

neebah

I would like to move some tags from xmp-subject to xmp-type based on whether the subject contains a specific term within a tag.  So I guess checking via a conditional.  So like if the subject contains a tag that contains a word then move it over to the type tag

Phil Harvey

Something like this maybe?:

exiftool -if "$subject =~ /\bWORD\b/" -xmp:type=WORD DIR

or do you want to add the word to existing Type list, and also remove the word from the Subject?:

exiftool -if "$subject =~ /\bWORD\b/" -xmp:type+=WORD -xmp:subject-=WORD DIR

Do you want to match subject items containing the word, or just items that are exactly the word?  Probably an exact match makes more sense, because otherwise the -xmp:subject-=WORD won't work:

exiftool -if "$subject =~ /(^|, )WORD(, |$)/" -xmp:type+=WORD -xmp:subject-=WORD DIR

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

neebah

I would like to transfer the tag based on whether or not it contains a substring. 

neebah

So if the subject tag contains "Digital:05:2005:001" and that's the only subject contain that contains the word digital I would like to move it based on it containing the word digital. 

Phil Harvey

So if one subject item contains the string "Digital" and the Subject contains more than one item, do you want to move just that item, or all items?  And what happens if more than one item contains the string?

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

neebah

I'm handling that by being choosy on the substring :)  So no two subject tags will have the same substring. 

neebah

So I just want to copy the item that contains the substring.  Or lets say the first item that contains the substring. 

neebah

The tag can continue to exist in the subject structure. 

Phil Harvey

OK, maybe this will do:

exiftool -if "$subject =~ /WORD/" "-xmp:type+<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}" DIR

If you want to also delete this item from the Subject list, add this to the command:

"-xmp:subject-<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}"

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

neebah


neebah

Okay mild hangup.  What should WORD be if I want to move the tag containing the word "Digital"  Should it just be digital in both spots?

Phil Harvey

"Digital" in both spots.

Actually, you can do it like this too and avoid the -if:

exiftool "-xmp:type+<${subject;s/^(.*, )?(.*?Digital.*?)(, .*)?$/$2/ or $_=undef}" DIR

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

neebah

It transferred the entire contents of the subject tag over instead of the single tag. 

Phil Harvey

What is the actual Subject that you started with?  (exiftool -subject FILE)

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