News:

If this site goes down it is because of the crappy DreamHost web hosting: They will disable your "unlimited traffic" web server if a single bot hammers the site with a moderate load.  If necessary, an alternate ExifTool forum page is available at https://sourceforge.net/p/exiftool/discussion/

Main Menu

How can I replace a substring in UserContent

Started by mike1950r, February 05, 2022, 11:35:04 AM

Previous topic - Next topic

mike1950r

Hello,

we need to replace a part of the value in UserContent, with another part, or just nothing to remove this part.
Could we please get an idea, how we can do this.

Thanks in advance.

cheers mike

StarGeek

First you need to figure out what tag is "UserContent" (see FAQ #3) as exiftool doesn't have a listing for a tag by that name.

Once you figure out the actual tag, then to remove it the command would be
exiftool -TAG= /path/to/files/

To replace a part, you would use
exiftool "-TAG<${TAG;s/SEARCH/REPLACE/g}" /path/to/files/
* 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).

mike1950r

Hello,

thanks StarGeek.
This works fine exept one Character '|'
This character is not replaced.

Is this a special perl character?
What can i do?

I have to replace "| and a word".

Thanks for assistance.

cheers mike

StarGeek

The pipe character is a special character in regex.  If you need to use any of these characters
. ^ $ * + - ? ( ) [ ] { } \ | — /
then you need to escape it with a backslash. So "| and a word" would become "\| and a word".
* 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).

mike1950r

Thank you very much, StarGeek,

This is working fine.

So it's possible to append a value with following conditions:
1) append only if Tag already exists
2) append only if value to append not already exists.

Very flexible indeed.

Cheers mike

StarGeek

Quote from: mike1950r on February 05, 2022, 01:36:19 PM
1) append only if Tag already exists

exiftool "-TAG<$TAG more text" /path/to/files/
Any file that doesn't already have the TAG will fail with a "No writable tags set" error, but you can ignore that

Quote2) append only if value to append not already exists.

A bit more complicated and you have to make sure it's unique, but you can use the -if option
exiftool -if "not $TAG=~/more text/" "-TAG<$TAG more text" /path/to/files/

An example of what I mean by unique.  If the above command found a file with "more texture", then the "more text" would match and it would be skipped.  This can be compensated by using a more exacting regular expression.
* 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).

mike1950r

Hi StarGeek,

we use following with success:

exiftool -if $UserComment -UserComment<${UserComment;s/APPENDTEXT//g} APPENDTEXT ...

1) Append only if UserComment tag exists
2) Append only if APPENDTEXT not already exists

Works exellent.

cheers mike

mike1950r

Hi StarGeek,

does your command: -if "not $TAG=~/more text/" "
mean more text is not a part in the tag value, or does it mean it is not the tag value?

Also how can i use two if conditions?
-if $UserComment
and
-if "not $TAG=~/more text/" "

Cheers mike

Phil Harvey

You could do it like this:

-if "$usercomment and not $usercomment=~/more text/"

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mike1950r

Thanks Lot Phil,

Everything is really working fantasticly.
You are so helpful here in the forum,
also with the perl questions, which enables using the capabilities of exftool a lot.

This also works fine for removing a part of the tag value:
-if $usercomment and $usercomment=~/REMOVETEXT/ -UserComment<${UserComment;s/REMOVETEXT//g}

Thanks lot again.

Cheers mike