swapping %20 with space

Started by jeno, February 26, 2018, 10:39:22 PM

Previous topic - Next topic

jeno

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?

Stephen Marsh

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

StarGeek

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.
"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

Stephen Marsh

#3
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).

jeno

Thanks Stephen & StarGeek,

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