Main Menu

Characters substitution

Started by elhiero, May 14, 2024, 12:47:53 PM

Previous topic - Next topic

elhiero

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

StarGeek

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

elhiero

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/_/" "/}

Phil Harvey

I don't think this is what you want: tr/_/" "/

The tr operator translates single characters only, so this will translate _ to ", not " ".

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

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

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).