ExifTool Forum

ExifTool => Newbies => Topic started by: rwittich_de on October 03, 2020, 10:26:19 AM

Title: Copy information from one field to another
Post by: rwittich_de on October 03, 2020, 10:26:19 AM
Hello,

I am a new user of exiftool and I have a question:
I want to copy the information in the field "Sublocation" to the field "Description" in all jpg images in a folder. How can I do this?

Thanks for looking at my little problem

Reinhold
Title: Re: Copy information from one field to another
Post by: StarGeek on October 03, 2020, 10:39:18 AM
The basic command would be
exiftool "-Description<Sub-location" /path/to/files/

But make sure you check your data first with the command in FAQ #3 (https://exiftool.org/faq.html#Q3) because you're asking to copy from an IPTC IIM/Legacy tag to an XMP IPTC Core tag.  It may be that you want to copy from Location, which is an IPTC Core tag, instead of Sub-location.

This command creates backup files.  Add -Overwrite_Original (https://exiftool.org/exiftool_pod.html#overwrite_original) to suppress the creation of backup files.  Add -r (https://exiftool.org/exiftool_pod.html#r-.--recurse) to recurse into subdirectories. 
Title: Re: Copy information from one field to another
Post by: rwittich_de on October 03, 2020, 10:47:04 AM
Thanks StarGeek,

this works perfect. What if I want to combine some fields like:

exiftool "-Description<Sublocation+City+Country" *.jpg

Is this ok?

Thanks

Reinhold
Title: Re: Copy information from one field to another
Post by: StarGeek on October 03, 2020, 11:34:44 AM
To include multiple tags and static data (such as spaces), you need to put a dollar sign in front of the tag names.
exiftool "-Description<$Sub-location $City $Country" /path/to/files/

If there is already a description and you want to add to that
exiftool "-Description<$Description $Sub-location $City $Country" /path/to/files/

This will fail, though, if Description doesn't already exist.  To cover the possibility that Description may or may not exist, you would use
exiftool "-Description<$Sub-location $City $Country" "-Description<$Description $Sub-location $City $Country" /path/to/files/

Title: Re: Copy information from one field to another
Post by: rwittich_de on October 03, 2020, 11:51:25 AM
Thanks again, StarGeek. I would never find by myself that the $ Sign is to add strings. I tried + and & but $ I would never try.
Now I have this:

exiftool "-Description<$Sub-location, $City, $Country"  *.jpg

This works in most cases, but if there is no city in the data, I get an error message. I would like to get a space or nothing. But it stops without adding the country. Is there a fix for that?

Thanks

Reinhold
Title: Re: Copy information from one field to another
Post by: StarGeek on October 03, 2020, 12:20:14 PM
Quote from: rwittich_de on October 03, 2020, 11:51:25 AM
Thanks again, StarGeek. I would never find by myself that the $ Sign is to add strings. I tried + and & but $ I would never try.

It's in the fourth paragraph under the -TagsFromFile option (https://exiftool.org/exiftool_pod.html#tagsFromFile-SRCFILE-or-FMT), which is what the "-TAG1<TAG2" construct is shorthand for.

If there's a chance that any one of the tags may be empty, it can get really messy. The basic rule is that any time a tag is assigned a value more than once, then the last assignment that can be executed will work.  So you could try this
exiftool "-Description<$Sub-location, $Country" "-Description<$Sub-location, $City, $Country" *.jpg

If City exists, than the second assignment will be executed.  If it doesn't exist, then the command will fall back to the first assignment.
Title: Re: Copy information from one field to another
Post by: rwittich_de on October 03, 2020, 04:13:40 PM
Thanks again StarGeek. This workes perfect. I am very happy that I found this forum and I found such a great specialist like you.  If you like you can see the results of your help in a few days at my homepage www.wittich.com.
Many thanks and best wishes.
Reinhold
Title: Re: Copy information from one field to another
Post by: rwittich_de on October 04, 2020, 04:34:10 AM
Now I found another problem, I don't know if it comes from Exiftool. I have a string in descriprion, like street, city, country. That is perfect. If I upload it to my homepage and try to display it with Gmedia gallery, it is not visible. But if I change only one letter in this description it becomes visible. I do not understand this. What is the difference between a string generated by Exiftool and a string generated by me?
I hope some knows what to do.
Best wishes
Reinhold
Title: Re: Copy information from one field to another
Post by: rwittich_de on October 04, 2020, 07:32:51 AM
Found a fix:

exiftool -Overwrite_Original "-headline<$Sub-location, $Country." "-headline<$Sub-location, $City, $Country."  *.jpg
Title: Re: Copy information from one field to another
Post by: StarGeek on October 04, 2020, 09:58:57 AM
Another case of the interface using different names than the actual names of the tags.  If you run across any other problems along the same lines, you can download a test file with about 1,400 tags filled out from this thread (https://exiftool.org/forum/index.php?topic=9212.0).