Writing text tto caption w quotes and apostrophes

Started by Archive, May 12, 2010, 08:53:51 AM

Previous topic - Next topic

Archive

[Originally posted by webmaestro on 2005-10-11 23:10:25-07]

Thank you for developing, releasing and supporting this powerful tool.

I see plenty of examples showing exiftool writing single words to keywords and the like, but I don't see many indicating how to write larger blocks like this:

May 22, 2002; Paris, FRANCE; MONICA BELLUCCI as Alex in the action, horror, crime, thriller "Irreversible" directed by Gaspar Noe.

In addition, we have photos who have apostrophes in their names (e.g., O'Malley).

I guess I could use double quotes like this:

exiftool -Source="O'Malley" filename.jpg

But I'm at a loss as to how to handle Caption items which may have both in them.

Any ideas?

Archive

[Originally posted by exiftool on 2005-10-12 13:14:51-07]

There are different ways to handle this, and the techniquees may be different for different command shells.  I will describe some techniques that work with common shells (sh, csh, tcsh, bash, zsh):

Characters can be escaped individually with \, so quotes don't have to be used at all, but then you have to escape each space character too.  This works in sh, csh, tcsh, bash and zsh.  (Note: in the following examples, '>' indicates a command shell prompt):

Code:
   > exiftool -comment=He\ said\ \"It\'s\ only\ a\ scratch\" test.jpg
    > exiftool -comment a.jpg
    Comment                         : He said "It's only a scratch"

An alternative is to use quotes but change quote types when necessary.  Adjacent quoted strings are concatinated.  This may be a bit confusing, but also works with sh, csh, tcsh, bash and zsh:

Code:
   > exiftool -comment='He said "It'"'s only a scratch"'"' test.jpg

Or maybe a combination of these two technniques is the best general solution:

Code:
   > exiftool -comment='He said "It'\''s only a scratch"' test.jpg

But probably the nicest way to do it is to use double quotes around the comment and escape any double quotes within the string.  Unfortunately this doesn't work for csh or tcsh, but does work with sh, bash and zsh:

Code:
   > exiftool -comment="He said \"It's only a scratch\"" test.jpg

I hope this helps.  If you have questions about your specific shell, try consulting your man pages.

Archive

[Originally posted by webmaestro on 2005-10-12 19:43:30-07]

Thank you for the speedy response. I already knew about the quotes, nested quotes and escaping quotes and spaces, but I was hoping you had additional tips and tricks. You did... you told me about some of the <flamebait>limitations</flamebait> of the csh and tcsh shells. :-)

I ended up figuring out much of it through trial and error, and determined that the info can be double-quoted as long as I convert all double quotes in the text into single quotes (I convert them because we have other operations which get finicky w double-quotes).

FYI: we are using ExifTool on an Apple Xserve running Mac OS X Server (v10.3.8 I believe). I tend to work in bash, but that box's administrator prefers tcsh, so I think it's running in tcsh if we care. We may have to drop into a different shell to run this command.

Thank you again for this wonderful tool!

Web Maestro Clay

Archive

[Originally posted by exiftool on 2005-10-12 21:00:26-07]

What you are doing to convert the quotes should work with csh too.

Thank you again for this wonderful tool!

You're welcome! - Phil