character replacing during output

Started by bs1925, July 17, 2016, 10:46:28 AM

Previous topic - Next topic

bs1925

Hi

for isolating hierachical keywords I use -xmp-lr:HierarchicalSubject to write to a text file. Afterwards I search and replace "," by ";" and "|" by " > ".

How can I do this during running exiftool and already write the replaced characters to the text file?

regards
Bernd

StarGeek

It sorta depends upon what you're doing with the text file.  If you're just reading it, then you can do something like this:
exiftool -p "$filename ${HierarchicalSubject;tr/,\|/;>/}" >output.txt FilesOrDir
That will output a list of filenames and their HierarchicalSubject. Not highly formatted, but quick and simple.

If you need to process the output with a script or something similar, then you're better off making a user defined tag, something like this:
MyHS=> {
Require => 'HierarchicalSubject',
ValueConv => q{
my $hs = join('; ',(ref $val ? @$val : ($val)));
$hs =~ tr/\|/>/;
return $hs;
},         
},


Example output (HS is my shortcut for HierarchicalSubject, easier than typing the whole thing out every time):
c:/ exiftool -hs -myhs Z:\Pictures\Camera_Pictures\San_Diego_Zoo\2010-05-15\2010-05-14_12.58.08.Jpg
Hierarchical Subject            : Animals|Marsupials|Koala, Settings|San Diego Zoo
My HS                           : Animals>Marsupials>Koala; Settings>San Diego Zoo

"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

bs1925

wow - the first quick and simple command works perfect! THX

one additional question - I would have to replace the "|" with " > " - there is a space character before and after the ">" - how does this work?

regards
Bernd

Hayo Baan

Instead of the simple tr/,\|/;>/ use the following tr/,/;/; s/\|/ > /g

tr/,/;/ will replace all occurrences of , with ;, s/\|/ > /g will substitute all | with " > ".
Hayo Baan – Photography
Web: www.hayobaan.nl

bs1925

#4
works perfect! THX

I only need a simple list with filename and the hierarchical keywords.
last question: how can I adopt the command to print only the filename without any extensions?

ie exiftool -p "$filename ${HierarchicalSubject;tr/,/;/; s/\|/ > /g}" >output.txt key.jpg

regards
Bernd

Hayo Baan

You could try something like this exiftool -p "${filename;s/\.[^.]+//} ${HierarchicalSubject;tr/,/;/; s/\|/ > /g}" >output.txt key.jpg
Hayo Baan – Photography
Web: www.hayobaan.nl

bs1925

I tried to understand the used perl commands - got it, more or less ;-(

so, inserting "$/" within -p represents a newline - but how can I seperate the two fields with a tabulator?
I cannot find this option.

regards
Bernd

Phil Harvey

#7
Hi Bernd,

You can put a tab directly in the -p argument -- it will come straight through in the output.  The only problem would be if your shell intercepts the tab character, which is quite likely as it turns out.  I don't have much time right now to think of a way around this, but I'll come back later with a solution.

- Phil

Edit:  On a Mac, a tab is entered by pressing CTRL-V then TAB.  I don't know about Windows.
...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 ($).