Help with counting and trimming comma separated values from a CSV field

Started by JustDrive, June 07, 2017, 04:21:42 PM

Previous topic - Next topic

JustDrive

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

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

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.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).