ExifTool Forum

ExifTool => Newbies => Topic started by: PL2020 on May 17, 2020, 05:55:28 AM

Title: Moving values from one field to another
Post by: PL2020 on May 17, 2020, 05:55:28 AM
Hi

I want to write a command to cut the value from IPTC Creator: Website and paste the valueto Description

Also, I want to apply a logic that the Creator: Website value contain a specific string (say YouTube)

I dont think there are built-in options for this

How can I write a command for this need?



Title: Re: Moving values from one field to another
Post by: StarGeek on May 17, 2020, 12:12:36 PM
Your question is a bit light on the details.  What does the tag currently look like and how do you want it to end up.
Title: Re: Moving values from one field to another
Post by: PL2020 on May 22, 2020, 09:47:03 AM
Currently, I have a bunch of photos with the following metatdata
Creator: Website = http://www.example.com/userid=1234567
Description = blank

I want to change the metadata into
Creator: Website = blank
Description = ID 1234567

Title: Re: Moving values from one field to another
Post by: StarGeek on May 22, 2020, 12:40:29 PM
Ok, so you want to take the trailing numbers from whatever your creator tag is?
exiftool -if "$TAG=~/\d+$$/" "-Description<${TAG;m/(\d+$)/;$_=$1}" -TAG= /path/to/files/

Replace TAG with the name of the tag you're copying from and blanking.  I added an IF to make sure you don't remove data that might not have the trailing numbers.

Title: Re: Moving values from one field to another
Post by: PL2020 on June 01, 2020, 10:42:04 AM
Quote from: StarGeek on May 22, 2020, 12:40:29 PM
Ok, so you want to take the trailing numbers from whatever your creator tag is?
yes

Do you think exiftool is the best for this purpose?

I tried but cannot understand the code :
Quote from: StarGeek on May 22, 2020, 12:40:29 PM

exiftool -if "$TAG=~/\d+$$/" "-Description<${TAG;m/(\d+$)/;$_=$1}" -TAG= /path/to/files/
Title: Re: Moving values from one field to another
Post by: StarGeek on June 01, 2020, 11:36:51 AM
As I said, you need to replace "TAG" with the actual tag you want to copy from and blank.  You need to figure out what that tag is.

Run this command to see all the tags in your file
exiftool -G1 -a -s /path/to/file/
Title: Re: Moving values from one field to another
Post by: PL2020 on June 06, 2020, 02:07:10 AM
exiftool has to create a new file

what can I do if I really need to edit and apply the desired change to the original file?
Title: Re: Moving values from one field to another
Post by: greybeard on June 06, 2020, 02:46:38 AM
Quote from: PL2020 on June 06, 2020, 02:07:10 AM
exiftool has to create a new file

what can I do if I really need to edit and apply the desired change to the original file?

Add -overwrite_original to your command

(It is good practice to backup your originals and/or carefully test your commands if you do this)
Title: Re: Moving values from one field to another
Post by: PL2020 on June 06, 2020, 07:38:23 AM
omg

I thought exiftool didn't have an option with such effect (why didn't I saw this when I went through the list of exiftool option ...... strange)

thanks a lot
Title: Re: Moving values from one field to another
Post by: StarGeek on June 06, 2020, 11:30:15 AM
Exiftool always creates a new copy of the file.  In the case of the Overwrite_Original option (https://exiftool.org/exiftool_pod.html#overwrite_original), it doesn't keep the backup file.

The edited file will also have the FileModifyDate changed to reflect the time of the edit. It can be avoided by adding the -P (preserve) option (https://exiftool.org/exiftool_pod.html#P--preserve).  But it should be noted that some backup software rely on that time stamp to tell if the file has been changed.
Title: Re: Moving values from one field to another
Post by: PL2020 on June 07, 2020, 07:03:45 AM
oh yes the -p option is what i'm looking for

are there fields that the -p option does not preserve?
Title: Re: Moving values from one field to another
Post by: StarGeek on June 07, 2020, 11:40:03 AM
That's -P. Capital P.  The lowercase p is the -p (printFormat) option (https://exiftool.org/exiftool_pod.html#p-FMTFILE-or-STR--printFormat).

Quote from: PL2020 on June 07, 2020, 07:03:45 AMare there fields that the -p option does not preserve?

Read the docs on the -P (preserve) option (https://exiftool.org/exiftool_pod.html#P--preserve) for full details.