I am trying to copy the filename to subject, removing underscores and filename extension:
exiftool -r -overwrite_original '-subject<${filename;s/\.[^\.]+$|_/ /g}' 'PATHtoFILEorDIRECTORY'
Which does exactly what I told it to, including replacing the filename extension with a space... However for good form, I would like to remove this trailing space. A case of just knowing enough to be dangerous I guess!
I poked around the forum and came up with the following:
exiftool -r -overwrite_original '-subject<${filename;s/\.[^\.]+$|_/ /g;-subject;s/\s+$//}' 'PATHtoFILEorDIRECTORY'
Which appears to remove the trailing white space, however it presents the following warning:
Warning: Useless use of negation (-) in void context for 'filename'
So is there a better way to do this with my original regex? If not, where have I gone wrong with the syntax combining the two regex and the subject tag? I of course tried subject without the hyphen, however this did not work.
Warning: Bareword "subject" not allowed while "strict subs" in use for 'filename'
Remove the 2nd -subect.
edit:
Now that I'm home and off mobile, I can be more clear. The second -subject; doesn't do anything and is the source of the error. It should be removed. Try this for your command:
exiftool -r -overwrite_original '-subject<${filename;s/\.[^\.]+$|_/ /g;s/\s+$//}' 'PATHtoFILEorDIRECTORY'
Thank you StarGeek!
So it appears to come down to adding three characters in order to string together two separate regex commands:
;s/
Is that correct?
Of course, when I went searching the web for info on combining separate Perl regular expressions, I did not find anything that simple... and the forum reference that got me half way there was from a different discussion (tag to filename, not filename to tag, so the syntax was different).
So rather than using the piple | for a "or" operator, I could achieve the same end result by stringing together three separate regex:
exiftool -r -overwrite_original '-subject<${filename;s/\.[^\.]+$/ /g;s/_/ /g;s/\s+$//}' 'PATHtoFILEorDIRECTORY'
EDIT:
Now that I think about it, I can now construct a better regex that only uses two expressions, without the need to correct the unwanted space as I no longer need to use the | pipe construct:
exiftool -r -overwrite_original '-subject<${filename;s/\.[^\.]+$//;s/_/ /g}' 'PATHtoFILEorDIRECTORY'
Thank you!
Quote from: Stephen Marsh on August 06, 2017, 04:42:29 PM
Thank you StarGeek!
So it appears to come down to adding three characters in order to string together two separate regex commands:
;s/
Is that correct?
Not quite. It's the semicolon alone that indicates a separate statement. The
s/ is the start of a new regex substitution, but you can use a completely different perl command, such as
tr or even something as complex as
map or
grep or even define a new variable with
my.
Thanks again StarGeek, I think did see tr in another topic, however I could not get it to work in a different context. This is really useful!