ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: Martin Z on May 30, 2023, 01:13:30 PM

Title: Request: CSV processing | including or excluding specific columns
Post by: Martin Z on May 30, 2023, 01:13:30 PM
Hi Phil, StarGeek, everyone,

I recently asked if it was possible to get EXIFtool to process only some of the columns when updating metadata from a CSV (or similarly, exclude one or more columns from the update). StarGeek kindly replied and confirmed that this isn't currently possible (and the -csv is essentially an "all or nothing" option) (https://exiftool.org/forum/index.php?msg=80052). Also, that using -TAG in combination with -CSV does not work.

Request
While I appreciate the above being the current situation, I wondered if it would be possible to consider enhancing the -CSV option so that:

Rationale

I realise that you likely have a queue of planning changes and so there is no guarantee that this change could be implemented any time soon, I hope however that you agree this would be a beneficial change to EXIFtool, would help users interact with EXIFtool more easily, and would make it easier for users to use EXIFtool to manage/update their metadata.

Thanks in advance!
Title: Re: Request: CSV processing | including or excluding specific columns
Post by: Phil Harvey on May 30, 2023, 07:13:45 PM
I can see how this could be useful.  I'll think about this.

- Phil
Title: Re: Request: CSV processing | including or excluding specific columns
Post by: wywh on May 31, 2023, 11:19:58 AM
It seems a quick workaround is to just make a copy of the .csv, delete unnecessary columns in the spreadsheet app, save, and use that as an input.

exiftool -overwrite_original -csv=out.csv .

... I have used .csv only to make a backup copy of my image and movie metadata, and to check errors in metadata. But now I have started to experiment how to copy that info back, if needed. Just the other day I manually copied ~200 metadata items from an old spreadsheet memo to movies (Keys) and in the process manually checked that everything was correct. But I'd rather not do that again manually...

- Matti
Title: Re: Request: CSV processing | including or excluding specific columns
Post by: Martin Z on June 01, 2023, 10:22:07 AM
Quote from: Phil Harvey on May 30, 2023, 07:13:45 PMI can see how this could be useful.  I'll think about this.   - Phil
Thanks Phil, that would be great!... Obviously just whenever you have time to fit this in is fine (Assuming you decide to implement it).



Hi Matti (@wywh (https://exiftool.org/forum/index.php?action=profile;u=8845)) -- Thanks for your comment / suggested workaround...

Quote from: wywh on May 31, 2023, 11:19:58 AMIt seems a quick workaround is to just make a copy of the .csv, delete unnecessary columns in the spreadsheet app, save, and use that as an input.
Generally speaking I'd say that is probably a pretty reasonable approach (and is basically what I am doing at the moment), however in my case part of the challenge is that I am running running EXIFtool with CSV datasets sometimes 10+ times a day and so manually editing the columns in each CSV file is a bit tedious.

NB: I have looked at automating the creation of a second CSV, specifically just for EXIFtool however as it is a work-in-progress (and my EXIF / EXIFtool knowledge grows bit-by-bit), I am continually having to edit this code (plus there are times when I might want to make exceptions, and produce a "non-standard EXIFtool CSV", which has to be done manually still), and hence thinking there might be a better way to address this. (Plus, having EXIFtool process the -TAG and --TAG parameters the same way (or at least very similar) whether you're working from a CSV or another method, seemed like generally a good idea.
Title: Re: Request: CSV processing | including or excluding specific columns
Post by: StarGeek on June 01, 2023, 06:55:24 PM
Another option might be using programs like CSVKit (https://csvkit.readthedocs.io/en/latest/) or xsv (https://github.com/BurntSushi/xsv), which are command line programs that edit csv files in various ways.  You could pipe the output from them directly into exiftool along these lines

xsv <some commands> | exiftool -CSV=- /path/to/files/
Title: Re: Request: CSV processing | including or excluding specific columns
Post by: Martin Z on June 17, 2023, 04:12:01 AM
Quote from: StarGeek on June 01, 2023, 06:55:24 PMAnother option might be using programs like CSVKit (https://csvkit.readthedocs.io/en/latest/) or xsv (https://github.com/BurntSushi/xsv), which are command line programs that edit csv files in various ways.  You could pipe the output from them directly into exiftool along these lines... xsv <some commands> | exiftool -CSV=- /path/to/files/

Thanks @StarGeek.

-- I had quick look into CSVKit (https://csvkit.readthedocs.io/en/latest/), it seems quite useful but I think it's python-based right(?) - if so, I have only written 1 script in python so don't really know it very well at all (need to try at some point as it does keep popping up admittedly)

-- In terms of CSV manipulation or creating secondary CSV's I accept that this can be done (is a valid workaround), in fact I do already do this in my main PowerShell script that runs the whole workflow. The issue is I am already up to 3 CSV's per file...



Just to be clear, I'm not trying to be super-forceful on this point (I accept that you, Phil and others are busy and this request may not get implemented for a while (or maybe even never), that's fine - just wanted to shed a bit more light on my wider workflow and why it's not as easy as just say doing CTRL+C / CTRL+V my current CSV and delete a column or two 👍🏼
Title: Re: Request: CSV processing | including or excluding specific columns
Post by: StarGeek on June 17, 2023, 03:17:06 PM
Quote from: Martin Z on June 17, 2023, 04:12:01 AM-- I had quick look into CSVKit (https://csvkit.readthedocs.io/en/latest/), it seems quite useful but I think it's python-based right(?) - if so, I have only written 1 script in python so don't really know it very well at all

You don't need to know python.  You just have to have Python installed and then you use it like any command.  And the install is usually easy.  For csvkit, you would use
pip install CSVKit[/quote]

And from there, it's just getting to know the details on the various options.

There are a lot of pretty neat python scripts on github that can be used for very specific purposes.

Title: Re: Request: CSV processing | including or excluding specific columns
Post by: Martin Z on June 18, 2023, 04:20:33 PM
Quote from: StarGeek on June 17, 2023, 03:17:06 PMYou don't need to know python.  You just have to have Python installed and then you use it like any command.
Ah OK cool -- so it's more like a free-standing app that I can run/call from the (windows) cmd line, rather than being (just) a python module* that can that I can import into my existing existing python script (which is my case, I wouldn't have)...  *I realise that it is likely available as a python module too, but my point/initial concern was that this was the only way to use it.

Like I say, I will put it on my list of things to look into (can't promise when, but I do appreciate you sharing it none-the-less.

FYI for anyone interested, here is a quick comparison against PowerShell (i.e. the tool I'm currently using to do this stuff) for their listed use-cases on the homepage. [Key: ⬆️ Better than PowerShell  |  🟢 Same as PowerShell  |  🟡 Dubious/can't comment]...

* Just from having tried to this myself recently, converting structured / hierarchical data (like JSON) to tabular data (like CSV) and getting a nice clean output is not easy.
Title: Re: Request: CSV processing | including or excluding specific columns
Post by: Phil Harvey on January 06, 2025, 07:13:51 PM
ExifTool 13.03 adds the ability to include or exclude specified columns from the CSV import, and 13.12 will expand this ability to allow group names and/or wildcards to be used when specifying which columns to import:

            Specific tags may be imported from the CSV database by adding -TAG
            options to the command, or excluded with --TAG, with exclusions
            taking priority.  Group names and wildcards are allowed.  If no
            tags are specified, then all except FileName and Directory are
            used.  Tags are imported in the same order as the database
            entries.

- Phil