Author Topic: Comma-space issue for empty variables  (Read 656 times)

Offline Lucuma13

  • Newcomer
  • *
  • Posts: 2
    • View Profile
Comma-space issue for empty variables
« on: February 20, 2023, 09:39:07 AM »
I am running Photo Mechanic version 6.0, build 6738 (5753775) on macOS Ventura 13.2.

I am using PM to add metadata to a large amount of pictures. Upon export, I need to create a TSV with different columns, and one of them should contain comma-separated values including several of my PM variables: "{keywords}, {persons}, {identity}".

My issue is that the previous command will export an unnecessary comma-space whenever one of the variables is blank. (E.g. if {persons}=blank, then output is "keyword1, keyword2, , identity1, identity2"). How could I prevent that behaviour (output should be "keyword1, keyword2, identity1, identity2")? Is there any function for smart appending (adds a comma-space only if the variable is not blank) or a piece of code based on grep/sed that I could use on the text export panel? Any advice on how to fix it or a workaround will be very appreciated!



Offline ahoward

  • Camera Bits Staff
  • Hero Member
  • *****
  • Posts: 852
    • View Profile
Re: Comma-space issue for empty variables
« Reply #1 on: February 20, 2023, 01:08:16 PM »
I can say that there is no way to do this directly in Photo Mechanic, as we do not have a way to apply logic to the output of the text exporter. I've spent some time trying to work out a solution for you but not being an expert with this stuff I haven't come up with one yet. Of course a quick find-and-replace in a text editor  seems like it would do it, and I ran this sed command:

sed 's/ ,//g' inputfile.txt > outputfile.txt

which removed all of the instances similar to your example, however it does not deal with lines that may end up ending with comma if the last variable returns nothing. If I figure out a way around that I will post an update.