ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: desgphoto on May 09, 2010, 11:01:25 AM

Title: Line breaks and "code replacement"
Post by: desgphoto on May 09, 2010, 11:01:25 AM
Hi,

how can I remove line breaks, special chars and/or single words from a XMP:description field? I'm pretty new with exiftool and have studied the docs and the forum to find a solution for this problem. Currently, I found this piece of code:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        NewCaption => {
            Require => 'Caption-Abstract',
            ValueConv => '$val =~ s/[\n\r]+/ /g ? $val : undef',
        },
        NewDescription => {
            Require => 'XMP:Description',
            ValueConv => '$val =~ s/[\n\r]+/ /g ? $val : undef',
        },
    },
);


But I can do whatever I want - it will not work for me. In principle I need to replace some words within the XMP-dc:description and the XMP-dc:author field, but I really don't no how....


Please can you help me.
Thanks a lot.
Title: Re: Line breaks and "code replacement"
Post by: Phil Harvey on May 10, 2010, 05:59:10 AM
You're looking in the right place.  The example you found converts linefeeds to spaces in XMP:Description.  You can also replace words like this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        NewDescription => {
            Require => 'XMP:Description',
            ValueConv => q{
                $val =~ s/[\n\r]+/ /g;
                $val =~ s/\bthis\b/that/g;
                return $val;
            },
        },
    },
);
1; # end


This will translate newlines to spaces and replace all "this" to "that".  The "\b" are used to indicate word boundaries so that "this" isn't replaced inside another word.

The command line you use is:

exiftool "-xmp:description<newdescription" FILE

See the config file documentation (https://exiftool.org/config.html) for details about how to install the configuration file above.

You can do exactly the same thing for XMP-dc:Author.

- Phil
Title: Re: Line breaks and "code replacement"
Post by: desgphoto on May 20, 2010, 03:01:12 PM
Hi Phil,

sorry for my late response but thanks a lot for the help. It really works great now! My fault was that I didn't knew really how to access the template from the config file.

"-xmp:description<newdescription"


Cheers,
Lars