Removing Tags with Spaces in them

Started by lewisn, March 31, 2016, 10:22:03 PM

Previous topic - Next topic

lewisn

Phil, I have a slide scanner that puts 14 spaces in the EXIF:ImageDescription tag.  I can see them when I print the tag value using -p %FMTFILE% (using  $EXIF:ImageDescription to print the tag within the fmt file).   The spaces seem to be trimmed by exiftool in other listings.   I know the tags are there, also, as I can also see them and edit them in some of the metadata editors I use.

Is there an easy way to delete these tags from the exiftool command line?

I confirmed that this doesn't work:
exiftool -EXIF:ImageDescription= test.jpg
You noted in the Forum elsewhere that this deletes the tag when the tag doesn't exist or is an empty string ("").

I cannot get this to delete the tag unless I put 14 spaces in quotations after the = sign as in:
exiftool "-EXIF:ImageDescription=              " test.jpg

Is there a way delete the tag for an arbitrary length of just white space.   I can imagine using the tag editing syntax to trim the tag in a -tagsfromfile copy to trim the spaces, but how do I also get it to delete the tag?  I could imagine a second pass after trimming the tag, by doing the above followed by another pass using  "-EXIF:ImageDescription="   to then delete the tag.  But since the tag always starts with the original tag value this would have to be done in another pass wouldn't it?

I actually want to do this in a larger command script that's also doing a number of other tag adjustments so would like to avoid a second pass if possible.   Throwing in an -execute doesn't cause the second operation to pick up the updated tag value does it?

Suggestions?

Thanks!


StarGeek

Your first command should work.  Do you have an example file that doesn't work that you can share?  Try FAQ #3 and make sure that it's EXIF:ImageDescription and not something else.  I see three other ImageDescription tags in the Tag Name section, though they seem to be unlikely candidates.


"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

lewisn

I tried it again and it deleted the tag ok, so now I'm confused.   When I was testing this earlier I actually had some other things on the command line with it, and I wasn't able to get a match until I counted out the 14 spaces.   My apologies for not actually trying the line as I listed it above.  I was away from my computer when I wrote it up.   By the way I posted another query earlier today and did try each of the examples in that posting carefully before posting.  Not sure at this point what I did the first time on this one.
Thanks!

Phil Harvey

#3
If the existing ImageDescription was 14 spaces and you tried -ImageDescription-=XXX, then it would only work if XXX was 14 spaces.  (-= is used to conditionally delete a tag.) Perhaps this is what you were doing.

- Phil

Edit:  Judging from your other post, maybe my guess was correct.
...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 ($).

lewisn

#4
Opps!  Yes, I just realized I put "="where I meant to put "-=" in the original post.
The post wouldn't have made sense without that!  With those corrections I have verified the behavior I describe in the post.

Summarizing:
I hoped to include something like the following in some scripts I have:
exiftool -TAG-= test.jpg
   - I want it to delete the tag if it is an empty string, or is a string of blanks.
exiftool -TAG-= -TAG=newstring test.jpg
   - I want it to set the tag to "newstring" if it is blanks, empty, or non-existent.
exiftool -TAG-= -addtagsfromfile @ "-TAG<SOMEOTHERTAG" test.jpg
   - This is a third example of what I want to do, this time copying the contents of "SOMEOTHERTAG" to TAG under the same 3 conditions.

As you state elsewhere the "-TAG-=" syntax tests whether the tag doesn't exist or is an empty string (""), but it doesn't catch a tag filled with spaces.  I have lines like the above in a general clean-up script I use, but they don't catch cases like I'd like them to where I want to delete or update tags if they contain only blank spaces.  Any suggestions on how to do this?

One way I can imagine doing this is to trim the tag in a separate operation first, using something like this:
"-TAG<${TAG;s/\s*$//}"
But if my understanding is correct I couldn't then follow this with any of the above commands referencing the trimmed tag since tags always refer to the original tag value in the file.  This would work if I did this in a separate pass, which I'm trying to avoid.    Do you have any suggestions on how I can trim blanks from a tag and refer to the trimmed value in subsequent operations in the same command line pass?

It would be nice if there was an option I could add that would cause ExifTool to trim trailing blanks from tags when doing -= conditional tests.

Thanks again for your help,
LewisN

Hayo Baan

Hi LewisN,

To remove tags with just spaces (or tabs, or newlines) in them, use this:
exiftool -TAG= -if "!defined $TAG || $TAG =~ /\A\s*\z/s"

To set it to some specific value when "empty", use:
exiftool -TAG="NEWVALUE" -if "!defined $TAG || $TAG =~ /\A\s*\z/s"

To set it to the value from another file when "empty", use:
exiftool -tagsfromfile @ "-TAG<OTHERTAG" -if "!defined $TAG || $TAG =~ /\A\s*\z/s"

Note: I use the \A and \z regular expression anchors together with the /s modifier instead of just the standard ^ and $ anchors to also capture empty strings with just newlines, but (more importantly) to not capture strings that may have an empty line in them but have other lines filled with text (e.g., in case of multiple paragraphs in a caption).

Cheers,
Hayo

PS: On a Mac, use single instead of double quotes.
Hayo Baan – Photography
Web: www.hayobaan.nl

lewisn

Thank you Hayo for your reply.  That's very helpful.  I incorporated your regular expression syntax checking for whitespace into a user defined tag that I wrote that checks whitespace in tags as it selectively copies caption data from other tags to Caption-Abstract if Caption-Abstract doesn't exist or is empty.

See: https://exiftool.org/forum/index.php/topic,7169.0.html

Thanks again,
LewisN