Author Topic: Help with counting and trimming comma separated values from a CSV field  (Read 1062 times)

JustDrive

  • Newbie
  • *
  • Posts: 3
Hey everyone, a noob here :)

Was wondering if there is a way to use ExifTool to do the following:

1) select a column from a csv file and then for each row in that column
2) count comma-separated words
3) if the count is 50 or under, leave everything as it is
4) if the count is over 50, remove the extra words *and here's the kicker* without removing the last 5 words (so, remove the 6th word from the end if there are 51 words, 6th and 7th from the end if there are 52 words etc.)

I have some very basic Python knowledge, but no idea where to start with ExifTool commands, if it's even possible to do that exact thing.

Thanks a lot in advance.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3794
Exiftool doesn't have CSV editing tools (AFAIK).

But you might take a look at CSV Kit.  It might have something you can use.  Though I think it's going to require some actual scripting.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3794
Upon further research, it doesn't seem like CSVKit has search/replace ability.

What OS are you using?  If Linux/Mac, you might be able to use sed.  I'm making some assumptions about how your csv is setup, but a Regex like this (s/^"((?:.*?,){45}).*,((?:.*?,){4})(.*?)"$/$1$2$3/) for just that column might work.  Applying it to just the one column would be the problem.

Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.