Search & replace characters in 'Comments' metadata field

Started by Russell, January 04, 2018, 09:16:34 AM

Previous topic - Next topic

Russell

Hi everyone

I have several thousand .jpg and .jpeg files, stored in multiple folders, with information about each one in the 'Comments' field of its 'Properties'.

I have used a 'dash' character (Alt+0150) in the 'Comments' field for most of these files, but I now want to replace the first occurrence of the 'dash' character with a 'colon' character – when I use exiftool to write the 'Comments' to a .csv file, the 'dash' character is shown as the three characters â€".

What is the code that I need to run to get exiftool to undertake this search and replace task, one folder at a time, please?

NOTE – I'm a novice when it comes to using exiftool, so please give an explicit break-down of whatever advice that you offer  ;) – thank-you.

Russell

Phil Harvey

Hi Russel,

The command will be something like this:

exiftool "-comment<${comment;s/-/:/ or undef $_}" -ext jpg -ext jpeg -r DIR

But the trick will be getting the encoding of "-" correct.  As a first attempt, try doing ALT+0150 instead of the "-" in the "s/-/" part of the command above.  Good luck.

I recommend running this on a test file first.  The command will preserve the original files with a "_original" added to the file name.  If you already have backups, the originals may be avoided by adding -overwrite_original to the command.  Or the originals my be deleted later with this command:

exiftool -delete_original -ext jpg -ext jpeg -r DIR

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

Russell

Hi Phil

Thank-you for getting back to me with a possible solution, and apologies for not having replied sooner.

Unfortunately, this hasn't worked. :-\

I created a Test folder containing only nine .jpg files and ran exiftool "-comment<${comment;s/-/:/ or undef $_}" -ext jpg -ext jpeg -r Test.

The following outcome message was displayed for each of the nine files:
   Warning: No writable tags set from Test/<filename>.jpg

I tried several more times, replacing at each attempt the '-' in the 's/-/' part of the command, with different characters, letters and numbers that I knew to exist in 'Comments' when looking at each file's 'Properties', but none were replaced and the same outcome message was displayed.  The following summary message was also displayed at the end of each run:
   1 directories scanned
   0 image files updated
   9 image files unchanged


Do you have any more advice about this please?

Thank-you.

Russell

Phil Harvey

Hi Russel,

What version of ExifTool are you using?  You should be able to reproduce this (with double quotes for Windows):

> exiftool -ver
10.75
> exiftool a.jpg -comment="test-this"
    1 image files updated
> exiftool '-comment<${comment;s/-/:/ or undef $_}' a.jpg
    1 image files updated
> exiftool a.jpg -comment
Comment                         : test:this


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

StarGeek

Assuming Windows, see here.

The Windows Comment property is saved to XPComment, so try that in your command rather than Comment.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Russell

Hi Phil and StarGeek

Thank-you for your further thoughts.

I'm using ExifTool version 10.75.

The command exiftool "-comment<${comment;s/-/:/ or undef $_}" -ext jpg -ext jpeg -r Test now works when comment is replaced with xpcomment – i.e. exiftool "-xpcomment<${xpcomment;s/-/:/ or undef $_}" -ext jpg -ext jpeg -r Test.

However, the command works only if I'm trying to replace a character or phrase that doesn't require me to use ALT+ to create the character, as you surmised at the outset, Phil.

I've run the following variations of the command, but none of them recognise the en dash character, or any other ALT+ character that I've tried:

exiftool "-xpcomment<${xpcomment;s/-/:/ or undef $_}" -ext jpg -ext jpeg -r Test

exiftool "-xpcomment<${xpcomment;s/ALT+0150/:/ or undef $_}" -ext jpg -ext jpeg -r Test

exiftool "-xpcomment<${xpcomment;s/U+2013/:/ or undef $_}" -ext jpg -ext jpeg -r Test

I've also run all three commands in PowerShell, including entering the en dash character directly using ALT+0150 in the command, where it's displayed correctly, but again, no joy.

Any further thoughts about how I can get ExifTool to recognise the en dash character please?

Thank-you.

Russell

Phil Harvey

Try adding the -L option to specify that you are using Windows Latin encoding, or the -charset CHARSET option if you are using a different system character set.

And you are holding the ALT key while typing the numbers on the numeric keypad when you say "ALT+0150" in your command?  I though it should only be 3 digits, so maybe you aren't.  Try holding ALT while typing "150" on the keypad to generate the character.  See FAQ 18 (and maybe FAQ 10) for some pointers.

Or maybe you could use HTML character entities.  Try adding -E when extracting, then replace the "-" in your subsitution with the HTML character entity.  Note that you may have to add a "\" before the "&" to escape this character in the substitution expression.  You will need the -E in the command when writing too.

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