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
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
I would like to transfer the tag based on whether or not it contains a substring.
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.
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
I'm handling that by being choosy on the substring :) So no two subject tags will have the same substring.
So I just want to copy the item that contains the substring. Or lets say the first item that contains the substring.
The tag can continue to exist in the subject structure.
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
Thanks Phil. I'll give it a try. :)
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?
"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
It transferred the entire contents of the subject tag over instead of the single tag.
What is the actual Subject that you started with? (exiftool -subject FILE)
- Phil
xmp subject
I meant the value of the tag. I want to be able to reproduce this.
Oh I see.
Subject : GPS/Manual, OriginalType/JPG, OwnerName/Name, Storage/Digital/06/2005/00001
It worked fine for me (note my quoting is different because I'm on a Mac):
> exiftool a.jpg -subject="GPS/Manual, OriginalType/JPG, OwnerName/Name, Storage/Digital/06/2005/00001" -sep ', '
1 image files updated
> exiftool a.jpg '-xmp:type+<${subject;s/^(.*, )?(.*?Digital.*?)(, .*)?$/$2/ or $_=undef}' -v2
======== a.jpg
Setting new values from a.jpg
Adding XMP-dc:Type
Rewriting a.jpg...
Editing tags in: APP1 XMP
Creating tags in: APP1 XMP
JPEG APP1 (310 bytes):
JPEG APP1 (5096 bytes):
Rewriting XMP
+ XMP-dc:Type = 'Storage/Digital/06/2005/00001'
JPEG DQT (130 bytes):
JPEG SOF0:
JPEG DHT (73 bytes):
JPEG SOS
1 image files updated
Could your problem perhaps be FAQ 17 (https://exiftool.org/faq.html#Q17)?
- Phil
Got it. Was attempting to use the exiftool direct option in exiftoolgui
Two more questions on this. How can I replace the tag with another value (once its found) and how can i simultaneously delete it from the subject tag
Replace it in XMP:Subject or XMP:Type?
If you want to copy the existing item to XMP:Type, then replace it in XMP:Subject, the command is:
exiftool -if "$subject =~ /WORD/" "-xmp:type+<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}" "-xmp:subject-<${subject;s/^(.*, )?(.*?WORD.*?)(, .*)?$/$2/}" "-xmp:subject+=SOMETHING ELSE" DIR
- Phil