ExifTool Forum

ExifTool => Newbies => Topic started by: jeno on February 26, 2018, 10:39:22 PM

Title: swapping %20 with space
Post by: jeno on February 26, 2018, 10:39:22 PM
Hi,

May I know how am do swap %20 with a space in metadata, I assuming this can only be done using the Config file. Any example code please?
Title: Re: swapping %20 with space
Post by: Stephen Marsh on February 26, 2018, 11:51:18 PM
As a quick test, presuming that the keyword/subject metadata contained multiple %20 characters that needed to be changed to word spaces, the following regex appears to work (no special config file was used):

exiftool -subject'<${subject;s/(%20)/ /g}' FILE_or_FOLDER
Title: Re: swapping %20 with space
Post by: StarGeek on February 27, 2018, 12:12:54 AM
This would work fine with a normal string type tag, but in the case of a list type tag such as Subject or Keywords, it will convert the all the entries in the list into a single entry unless the -sep option is also used.

I prefer the -api filter option with -TagsFromFile, as processes each item in a list type tag separately.  (I'm far too attached to that option.)

exiftool -api "Filter=s/%20/ /g" -TagsFromFile @ -TAG -TAG2 -TAG3 FileOrDir

Replace each TAG with the tag you actually want to run the substitution on.  Replace FileOrDir with the files and/or directories that you want to process.
Title: Re: swapping %20 with space
Post by: Stephen Marsh on February 27, 2018, 12:27:36 AM
Ah, you are of course 100% correct StarGeek, I should have tested with more than one keyword (I don't know how many times that this list tag issue has caught me out)!

So, presuming that a semi-colon ; separator was consistently used to separate the list keywords:

exiftool -sep ';' -subject'<${subject;s/(%20)/ /g}' FILE_or_FOLDER

I of course prefer your more elegant solution, at least I had the regex bit mostly right (I used a capture group, even though I was not back-referencing it in the replace).
Title: Re: swapping %20 with space
Post by: jeno on February 27, 2018, 04:46:40 AM
Thanks Stephen & StarGeek,

This line of code is what I was looking for:
$item =~ s/(%20)/ /g;