ExifTool Forum

ExifTool => ExifTool GUI => Topic started by: Jossie on February 22, 2013, 01:17:53 PM

Title: Replacing string in tag
Post by: Jossie on February 22, 2013, 01:17:53 PM
Good evening,

for obvious reasons it is not possible to enter a hyphen into a multiple value tag in EXIFtoolGUI. Now I have the tag PersonInImage and would like to add names with a hyphen in them, e.g. my own name. Since that is not possible I would like to use an underscore instead and later replace the underscores with a hyphen in a given tag for selected files.

I have searched the forum and the documentation but could not find a solution to this. I am sure there must be a simple command to do that.

Best wishes

Hermann-Josef
Title: Re: Replacing string in tag
Post by: Phil Harvey on February 22, 2013, 01:44:22 PM
Hi Hermann-Josef,

Simple?  No.  It requires the advance formatting feature of ExifTool...

On the command line, you could do this substitution with:

exiftool "-PersonInImage<${PersonInImage;tr/_/-/}" FILE

You can probably also accomplish this through the ExifTool Direct feature of ExifToolGUI.

- Phil
Title: Re: Replacing string in tag
Post by: Jossie on February 22, 2013, 01:48:01 PM
Hi Phil,

fast answer as ever! Thanks a lot.

It works and I'll put that line into my args-file that does the clean-up.

Many thanks and best wishes

Hermann-Josef
Title: Re: Replacing string in tag
Post by: Martin Z on June 18, 2023, 06:07:46 PM
Quote from: Phil Harvey on February 22, 2013, 01:44:22 PMexiftool "-PersonInImage<${PersonInImage;tr/_/-/}" FILE

Hi Phil,

I tried to adapt the above to do something quite similar but I couldn't seem to get it 🤔 I'd like to replace the 'x' in ImageSize with ' x ' (i.e. pad it with a space either side)...

Previous cmd  --> EXIFTool "-PersonInImage<${PersonInImage;tr/_/-/}" FILE
Understanding --> EXIFTool "-TagName<${TagName;tr/FindString/ReplaceString/}" FILE
Conversion    --> EXIFTool "-ImageSize<${ImageSize;tr/x/ x /}" FILE

> EXIFTool -ImageSize File.mp4
Image Size: 1920x1080

> EXIFTool "-ImageSize<${ImageSize;tr/x/ x /}" File.mp4
Expected output --> Image Size: 1920 x 1080
Actual output   --> Error renaming File.mp4

Am sure I've just missed something simple/obvious, but if you could please help me with the above and confirm the command syntax that would be great! 👍🏼

Thanks
- Martin
Title: Re: Replacing string in tag
Post by: Phil Harvey on June 19, 2023, 07:36:34 AM
Hi Martin,

You need to use s/// instead of tr/// for what you are trying to do (substitute instead of translate).

- Phil
Title: Re: Replacing string in tag
Post by: Martin Z on June 19, 2023, 10:01:26 AM
Quote from: Phil Harvey on June 19, 2023, 07:36:34 AMYou need to use s/// instead of tr/// for what you are trying to do (substitute instead of translate).

Thanks Phil, I updated the script (swapping 'tr' <--> 's') but I got another error I'm afraid...

> EXIFTool "-ImageSize<${ImageSize;s/x/ x /}" "File.mp4"
Warning: [minor] The ExtractEmbedded option may find more tags in the media data - File.mp4
    0 image files updated
    1 image files unchanged

Any idea what I'm doing wrong still? 🤔
Title: Re: Replacing string in tag
Post by: Martin Z on June 26, 2023, 07:04:23 AM
Quote from: Phil Harvey on June 19, 2023, 07:36:34 AMYou need to use s/// instead of tr/// for what you are trying to do (substitute instead of translate)

[UPDATE]: Code didn't work unfortunately but found another way to do this...
Title: Re: Replacing string in tag
Post by: Phil Harvey on June 27, 2023, 06:21:45 AM
This command should do the same thing:

exiftool -p "${ImageSize;s/x/ x /}" FILE

Your earlier command was trying to write the value of ImageSize, which of course doesn't work.

- Phil