Hello,
I would like to copy some parts of filenames into Caption-Abstract.
The template for my filenames is :
20240514-12:22-My_filename_had_underscores
I would like to get in the Caption-Abstract field :
My filename had underscores
I tried this
-k -L -IPTC:Caption-Abstract<${Filename;s/(.{15})(.*)_(.*)_(.*)_(.*)/$2" "$3" "$4" "$5/}
It works, but some files have 0,1,2,3, or more underscores in their names ...
I tried also -k -L -IPTC:Caption-Abstract<${Filename;s(_)(" ")}
Here, only the first underscore is replaced by a space ...
Thanks
The easiest thing to do would be to use the Perl tr operator.
exiftool -k -L "-IPTC:Caption-Abstract<${Filename;tr/_/ /}" /path/to/files/
Your second command only did one substitution because you didn't have the Global flag on it.
-IPTC:Caption-Abstract<${Filename;s(_)(" ")g}
You might want to consider using Basename instead of Filename because Basename doesn't include the extension.
Thank you very much.
I learnt today:
tr/ / /
s(_)(" ")g
basename
I can use now
-k -L -overwrite_original -IPTC:Caption-Abstract<${Basename;s/^.{15}//;tr/_/" "/}
I don't think this is what you want: tr/_/" "/
The tr operator translates single characters only, so this will translate _ to ", not " ".
- Phil
From the lack of quotes elsewhere, I'm assuming that this command is being used in Windows PowerShell.
PowerShell is so weird. The tag copy operation doesn't need quotes around it. I've got no clue as to how it decides that this isn't a redirection operation.
But the end result is that the quotes are needed to keep the space as part of the same argument.
Ah. Thanks.
- Phil