Author Topic: Howto remove a string from every occurrence?  (Read 2966 times)

FixEUser

  • Jr. Member
  • **
  • Posts: 29
Howto remove a string from every occurrence?
« 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?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2432
Re: Howto remove a string from every occurrence?
« Reply #1 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
« Last Edit: September 01, 2016, 03:48:51 PM by StarGeek »
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

FixEUser

  • Jr. Member
  • **
  • Posts: 29
Re: Howto remove a string from every occurrence?
« Reply #2 on: September 01, 2016, 02:44:22 PM »
Thanks a lot, StarGeek!!

FixEUser

  • Jr. Member
  • **
  • Posts: 29
Re: Howto remove a string from every occurrence?
« Reply #3 on: September 02, 2016, 11:48:13 AM »
I have a picture showing:
Code: [Select]
Supplemental Categories         : ACE, ENT, FAS
Url                             : http://www.gettyimages.com
Licensor URL                    : http://www.gettyimages.com
The Groupnames are 
Code: [Select]
XMP-getty 
Code: [Select]
XMP-photoshop and
Code: [Select]
XMP-plusWhatever 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?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2432
Re: Howto remove a string from every occurrence?
« Reply #4 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).  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.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

FixEUser

  • Jr. Member
  • **
  • Posts: 29
Re: Howto remove a string from every occurrence?
« Reply #5 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 simple
Code: [Select]
exiftool.exe -LicensorURL= picturename.jpgor
Code: [Select]
exiftool.exe -XMP-getty:LicensorURL= picturename.jpgIf I try to find some details, e.g. with
Code: [Select]
exiftool.exe -G picturename.jpgI get his result:
Code: [Select]
[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 with
Code: [Select]
exiftool.exe -XMP:LicensorURL= picturename.jpgNo luck.

With the help of the additional command -v
Code: [Select]
exiftool.exe -G -v picturename.jpgI get
Code: [Select]
[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:
Code: [Select]
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.

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 988
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: Howto remove a string from every occurrence?
« Reply #6 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?
Hayo Baan – Photography
Web: www.hayobaan.nl

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2432
Re: Howto remove a string from every occurrence?
« Reply #7 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?
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

FixEUser

  • Jr. Member
  • **
  • Posts: 29
Re: Howto remove a string from every occurrence?
« Reply #8 on: September 02, 2016, 06:20:09 PM »
The output is always:
Code: [Select]
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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14596
    • ExifTool Home Page
Re: Howto remove a string from every occurrence?
« Reply #9 on: September 02, 2016, 08:31:05 PM »
When the -v output says this:

Code: [Select]
  | [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
...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 ($).

FixEUser

  • Jr. Member
  • **
  • Posts: 29
Re: Howto remove a string from every occurrence?
« Reply #10 on: September 03, 2016, 03:55:40 AM »
Thank you Phil.

I use exiftool.exe v10.25 with the command
Code: [Select]
"exiftool -xmp -b picturename.jpg > out.xmp
The section with LicensorURL looks like this:
Code: [Select]
<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:
Code: [Select]
<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>

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14596
    • ExifTool Home Page
Re: Howto remove a string from every occurrence?
« Reply #11 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.

Code: [Select]
> 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
...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 ($).

FixEUser

  • Jr. Member
  • **
  • Posts: 29
Re: Howto remove a string from every occurrence?
« Reply #12 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?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14596
    • ExifTool Home Page
Re: Howto remove a string from every occurrence?
« Reply #13 on: September 04, 2016, 07:36:39 AM »
Rebuilding the XMP from scratch should do what you want.  This is similar to FAQ 20, except for the XMP:

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

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