Custom column headers for CSV export

Started by Schmidtze, July 16, 2017, 04:56:35 AM

Previous topic - Next topic

Schmidtze

Hello,

I'm using a command like this

  exiftool.exe -csv -gpslatitude

the resulting CSV output contains "GPSLatitude" of course as the header name for the latitude column.

My question: Is it possible to change this column header, for example to something like "Latitude"? This is only an example, I have a lot of columns which I have to rename to fit a requested format.

Many thanks in advance
Friedemann

StarGeek

Not directly.

I think you would have to create a user defined tag that took the value you wanted and just returned it.  Something like this (not sure it works, I haven't tested it)
Latitude => {
            Require => 'GPSLatitude',
            ValueConv => '$val',
        },

but if you have a lot, it might not be worth it.

I'd say, unless you have a lot of csv files to make, it might just be easier to load up the files and just replace the headers.
"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

Phil Harvey

You can do it like this:

exiftool -echo "SourceFile,Latitude" -p "$directory/$filename,$gpslatitude" DIR

This should work as long as the directory/filename doesn't contain a comma.

- Phil
...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 ($).

Schmidtze

Hi,

many thanks!

It works, a little bit  ;-) When using this:

exiftool.exe -csv -n -c "%.6f" -echo "a,b,c" -p "$gpslatitude,$gpslongitude,$gpsaltitude"

I get almost what I want, but only almost. The result is

a,b,c
34.14857,-118.225848333333,214
SourceFile


But I also can not absolutely rule out, that the result doesn't contain any commas. So I can't use it unfortunately. Maybe it's a feature request for future versions, for example something like this

exiftool.exe -csv -gpslatitude:"Latitude"

or

exiftool.exe -csv -gpslatitude["Latitude"]

Best regards
Friedemann



Phil Harvey

You should remove -csv from your command if using -p.

If values may contain commas, then add quotes around them in the -p argument.  (You'll have to figure out how to escape the quotes on your system to get quotes inside the argument.)

Adding an option to rename the columns is an interesting idea, but would break the CSV import feature (for which the column headings must be the same as the tag names).

- Phil
...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 ($).

Stephen Marsh

This is my first attempt at piping the output of ExifTool to another command, and also my first attempt at sed:

exiftool -gpslatitude -csv 'IMAGE.jpg' > 'DIR/FILE.csv' | sed 's/GPSLatitude/Latitude/g' 'DIR/FILE.csv'

Which I thought would work, but it did not... well the output is correct:

SourceFile,Latitude

However the file has not actually been changed.

Phil Harvey

Close, but the piping was wrong.  It should work like this:

exiftool -gpslatitude -csv 'IMAGE.jpg' | sed 's/GPSLatitude/Latitude/g' > 'DIR/FILE.csv'

- Phil
...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 ($).

Schmidtze

Hi,

I just noticed a strange bahaviour. I'm using this now

-n -c "%.6f" -echo "Image File Name,GPS Latitude,GPS Longitude,Altitude" -p "$filename,$gpslatitude,$gpslongitude,$gpsaltitude"


It works fine, and produces an output like this

Image File Name,GPS Latitude,GPS Longitude,Altitude
gstExifToolTest05011BDE.jpg,52.552185,13.411325,57


But when for example the file doesn't contain an altitude value, it fails completely and produces simply this:

Image File Name,GPS Latitude,GPS Longitude,Altitude


Honestly I except at least the filename and the coordinate values.

Am I doing something wrong? I'm working with an arg file containing the filenames.

Best regards
Friedemann

Phil Harvey

Hi Friedemann,

From the exiftool application documentation for -p:

            If a specified tag does not exist, a minor warning is issued and
            the line with the missing tag is not printed.  However, the -f
            option may be used to set the value of missing tags to '-' (but
            this may be configured via the MissingTagValue API option), or the
            -m option may be used to ignore minor warnings and leave the
            missing values empty.


(I should really stop quoting the documentation here because it won't reflect any future improvements.)

- Phil
...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 ($).

Schmidtze

Hi Phil,

oh, excuse me so much, yes, I had to read the documentation of "-p", sorry and thank you!!!

Best regards
Friedemann