ExifTool Forum

ExifTool => Newbies => Topic started by: FixEUser on September 01, 2016, 03:16:27 AM

Title: Howto remove a string from every occurrence?
Post by: FixEUser on September 01, 2016, 03:16:27 AM
I would like to remove a specifc string - lets say "Unwantend Text" - from every occurence in all my *.jpg files.

My problem is:
I don't know in which tags this "Unwanted Text" is stored.
If I look into a single *.jpg, this "Unwanted Text" can also be stored in multiple tags in the same file.

Could please someone help me to create the syntax to delete this "Unwanted Text" everywhere in all my *.jpg, but don't touch all the other informations?
Title: Re: Howto remove a string from every occurrence?
Post by: StarGeek on September 01, 2016, 03:54:13 AM
Make sure you have at least exiftool version 10.05.

At the very basic level, this command will do it.
exiftool -api "Filter=s/Unwanted Text//g" -tagsfromfile @ -all:all FileOrDir

This command is case sensitive.  To make it case insensitive, add an i after the g i.e "Filter=s/Unwanted Text//gi".  Additionally, this will remove the text even if it's part of a longer string.  "This is Unwanted Text" will become "This is ".  Finally, if "Unwanted Text" is the entire content of the tag, it will blank the tag but not remove it, though this isn't really a problem and won't affect the file.

edit: fixed stupid spelling error
Title: Re: Howto remove a string from every occurrence?
Post by: FixEUser on September 01, 2016, 02:44:22 PM
Thanks a lot, StarGeek!!
Title: Re: Howto remove a string from every occurrence?
Post by: FixEUser on September 02, 2016, 11:48:13 AM
I have a picture showing:
Supplemental Categories         : ACE, ENT, FAS
Url                             : http://www.gettyimages.com
Licensor URL                    : http://www.gettyimages.com

The Groupnames are  XMP-getty  XMP-photoshop and XMP-plus
Whatever I try, I cant get rid off this entries.

What can I do?

If I remove -ALL= tags, this tages are gone too.
But how can I remove them tag by tag?
Title: Re: Howto remove a string from every occurrence?
Post by: StarGeek on September 02, 2016, 02:18:35 PM
Now I'm a little confused.  Are you trying to get rid of the groups or of some text? 

What is the actual command you are using?

If you're trying to get rid of a group, you can, for example, use -XMP-getty:all to get rid of everything in the XMP-getty group.  But there may be other tags in that group than just Licensor URL.  A least, I think that's the group that tag is in.

If you are trying to get rid of "http://www.gettyimages.com", then that requires a little more work.  The s/Unwanted Text//g part of the command is a substitution using a RegEx (Regular Expression), which are very complicated (Tutorial here (http://www.regular-expressions.info/)).  In a regex the slash / and the dot . have a special meaning and need to be escaped with a backslash.  So to remove the url, you would need to use s/http:\/\/www\.gettyimages\.com//g instead.  Take note that using this as your filter, it would blank the Licensor URL and URL tags, but not remove them.

Supplemental Categories is a special case and I would be careful about using the filter option to remove stuff from it.  First, it is a list type tag.  That means each entry in that tag is separate from the others and are processed separately using api Filter.  So if you were trying to filter "ACE, ENT, FAS", it wouldn't work.  Additionally, items in that tag are often only 3 characters long and using api filter to remove one of them might have unintended consequences in other tags.
Title: Re: Howto remove a string from every occurrence?
Post by: FixEUser on September 02, 2016, 03:01:17 PM
Thanks again for your support and very helpful informations, StarGeek!

It was just a test with -ALL= to see if its possible to remove all the groups at all.
Removing specific text was my first question. Removing an entire tag like "Licensor URL" is my secondary goal.

But this doesn't seem to work with a simpleexiftool.exe -LicensorURL= picturename.jpg
or
exiftool.exe -XMP-getty:LicensorURL= picturename.jpg
If I try to find some details, e.g. with
exiftool.exe -G picturename.jpgI get his result:[XMP]           Supplemental Categories         : ACE, ENT, FAS
[XMP]           Url                             : http://www.gettyimages.com
[XMP]           Licensor URL                    : http://www.gettyimages.com

With this groupnames, I try it withexiftool.exe -XMP:LicensorURL= picturename.jpgNo luck.

With the help of the additional command -vexiftool.exe -G -v picturename.jpgI get [adding XMP-photoshop:CopyrightFlag]
  | CopyrightFlag = true
...
  | SupplementalCategories = ACE
  | SupplementalCategories = ENT
  | SupplementalCategories = FAS
  | [adding XMP-photoshop:url]
  | Url = http://www.gettyimages.com
  | [adding XMP-plus:LicensorURL]
  | LicensorURL = http://www.gettyimages.com
...
and know now the correct groupnames. But even with this information, the picture remains "unchanged", using: exiftool.exe -XMP-plus:LicensorURL= picturename.jpg

I'm lost, I don't understand how exiftool can show all this values, but doesn't let me remove them tag by tag.
Title: Re: Howto remove a string from every occurrence?
Post by: Hayo Baan on September 02, 2016, 03:18:25 PM
I'm quite sure any of your attempts to get rid of the licensorurl tag should have worked. Wat was did output exiftool generated on those commands? Did it tell you one file was updated? If so there should be a file with suffix _original. If not, then exiftool did not succeed, is your file perhaps write protected?
Title: Re: Howto remove a string from every occurrence?
Post by: StarGeek on September 02, 2016, 03:23:46 PM
As Hayo says, it should have worked.  My mistake on guessing XMP-getty was the group for LicensorURL.  XMP-plus is the correct group but both -LicensorURL= and -xmp:LicensorURL should have worked. 

What is the full output either of these commands produces?
Title: Re: Howto remove a string from every occurrence?
Post by: FixEUser on September 02, 2016, 06:20:09 PM
The output is always: 0 image files updated
1 image files unchanged

There is no _original file. The picturename.jpg remains unchanged.

I started the commandline as Admin. Should not be a write-protection problem.

But it's midnight actually. I try it again tomorrow.
Title: Re: Howto remove a string from every occurrence?
Post by: Phil Harvey on September 02, 2016, 08:31:05 PM
When the -v output says this:

  | [adding XMP-plus:LicensorURL]

It means that XMP-plus:LicensorURL is not pre-defined.  A tag must be pre-defined for you to be able to write it.

This tag is defined in the current version of ExifTool, so the problem is likely that you are running an old version.

Either that, or there is something wrong with the way this is written in the XMP so that ExifTool doesn't recognize the tag.  If you are already running the most recent ExifTool, then post the XMP (the output of "exiftool -xmp -b FILE > out.xmp") and your exact command and we can figure it out.

- Phil
Title: Re: Howto remove a string from every occurrence?
Post by: FixEUser on September 03, 2016, 03:55:40 AM
Thank you Phil.

I use exiftool.exe v10.25 with the command"exiftool -xmp -b picturename.jpg > out.xmp

The section with LicensorURL looks like this: <rdf:Description rdf:about=''
  xmlns:plus='http://ns.useplus.org/ldf/xmp/1.0/'>
  <plus:LicensorURL>http://www.gettyimages.com</plus:LicensorURL>
</rdf:Description>

The section with the Supplemental Categories:<rdf:Description rdf:about=''
  xmlns:photoshop='http://ns.adobe.com/photoshop/1.0/'>
  <photoshop:AuthorsPosition>Contributor</photoshop:AuthorsPosition>
  <photoshop:SupplementalCategories>
   <rdf:Bag>
    <rdf:li>ACE</rdf:li>
    <rdf:li>ENT</rdf:li>
    <rdf:li>FAS</rdf:li>
   </rdf:Bag>
  </photoshop:SupplementalCategories>
  <photoshop:URL>http://www.gettyimages.com</photoshop:URL>
</rdf:Description>
Title: Re: Howto remove a string from every occurrence?
Post by: Phil Harvey on September 03, 2016, 06:46:52 AM
The LicensorURL is written incorrectly.  It should be in a Seq of Licensor structures.  I don't have much time now so I can't check the other.

> exiftool a.xmp -licensorurl=x
    1 image files created
> cat a.xmp
<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 10.26'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about=''
  xmlns:plus='http://ns.useplus.org/ldf/xmp/1.0/'>
  <plus:Licensor>
   <rdf:Seq>
    <rdf:li rdf:parseType='Resource'>
     <plus:LicensorURL>x</plus:LicensorURL>
    </rdf:li>
   </rdf:Seq>
  </plus:Licensor>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?>


- Phil
Title: Re: Howto remove a string from every occurrence?
Post by: FixEUser on September 03, 2016, 07:30:57 AM
Thank you very much for your fast answer, Phil.

Is there any way to remove all "wrong" tags with exiftool?
Or what do you suggest to do in such cases?
Title: Re: Howto remove a string from every occurrence?
Post by: Phil Harvey on September 04, 2016, 07:36:39 AM
Rebuilding the XMP from scratch should do what you want.  This is similar to FAQ 20 (https://exiftool.org/faq.html#Q20), except for the XMP:

exiftool -xmp:all= -tagsfromfile @ -xmp:all FILE

- Phil