Main Menu

Replacing string in tag

Started by Jossie, February 22, 2013, 01:17:53 PM

Previous topic - Next topic

Jossie

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

Phil Harvey

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

Jossie

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

Martin Z

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

Phil Harvey

Hi Martin,

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

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

Martin Z

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? 🤔

Martin Z

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...
  • ❌ Using s/// (e.g. "-ImageSize<${ImageSize;s/x/ x /}" still gave me an error (see my earlier message)
  • ✅ Rather than keep bugging you, I was able to use MediaInfo to do this instead. NB: MediaInfo has a pseudo 'output template' feature where you can insert Tags as basically variables along with any other text (i.e. you can write your own XML file, and put the tags where you want them, a HTML file, a CSV file just using commas between tags, etc...

    > MediaInfo.exe --Output="Video;%%Width%% x %%Height%%" %1
    1280 x 720

     

Phil Harvey

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