I run a few cuddeback trap cams all the files get emailed me to named as T00001.jpg, T00002.jpg and the counter gets reset every email. I have a small bash script that can rename them by date/time from the createdate field, but I'd like to prefix them with an item from the UserComment field.
Depending on the model of the camera (I have two currently) the usercomment is one of these two:
MR=C.1,AD=3/10/2022,LD=38,BT=11,RD=36,LH=0,LI=22,BL=7959,BP=50%,BS=Ext,BD=37,BI=30,CF=Disabled,IR=Indoors,WL=850nm,EX=Centered,ID=TRIPOD,LO=001,MA=1B034C1A926E,SM=SUR,DD=FAP,DI=1,DV=OFF,DL=OFF,ND=FAP,NI=1,NV=OFF,NL=OFF
MR=C.1,AD=11/6/2020,LD=32,BT=12,RD=0,LH=0,LI=29,BL=5290,BP=50%,BS=Int,BD=0,BI=2,CF=Enabled,EX=Centered,ID=SFP,LO=005,MA=2818C978936E,SM=SUR,DD=FAP,DI=1,DV=OFF,DL=OFF,ND=FAP,NI=1,NV=OFF,NL=OFF
I'd like to prefix the filename with the ID= from it's Usercomment. I was using ID=$(exiftool -A $img | awk -F"[,=]" '/ID=/{print $34}')
exiftool -d $ID-%Y-%m-%d_%H%M%S%%-c.%%e "-filename<CreateDate" $img;
but that doesn't work with the other model because 34th value is not the ID in the 2nd entry I listed above.
Any thoughts?
You can use regex to extract the ID.
exiftool -d %Y-%m-%d_%H%M%S%%-c.%%e '-FileName<${UserComment;m/ID=([^,]+),/;$_=$1;}-$CreateDate' file.jpg
Example output
C:\>exiftool -G1 -a -s -CreateDate -UserComment y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
[ExifIFD] CreateDate : 2022:04:18 14:52:05
[ExifIFD] UserComment : MR=C.1,AD=3/10/2022,LD=38,BT=11,RD=36,LH=0,LI=22,BL=7959,BP=50%,BS=Ext,BD=37,BI=30,CF=Disabled,IR=Indoors,WL=850nm,EX=Centered,ID=TRIPOD,LO=001,MA=1B034C1A926E,SM=SUR,DD=FAP,DI=1,DV=OFF,DL=OFF,ND=FAP,NI=1,NV=OFF,NL=OFF
======== y:/!temp/Test4.jpg
[ExifIFD] CreateDate : 2022:04:18 14:52:05
[ExifIFD] UserComment : MR=C.1,AD=11/6/2020,LD=32,BT=12,RD=0,LH=0,LI=29,BL=5290,BP=50%,BS=Int,BD=0,BI=2,CF=Enabled,EX=Centered,ID=SFP,LO=005,MA=2818C978936E,SM=SUR,DD=FAP,DI=1,DV=OFF,DL=OFF,ND=FAP,NI=1,NV=OFF,NL=OFF
2 image files read
C:\>exiftool -d %Y-%m-%d_%H%M%S%%-c.%%e "-TestName<${UserComment;m/ID=([^,]+),/;$_=$1;}-$CreateDate" y:\!temp\Test3.jpg y:\!temp\Test4.jpg
'y:/!temp/Test3.jpg' --> 'y:/!temp/TRIPOD-2022-04-18_145205.jpg'
'y:/!temp/Test4.jpg' --> 'y:/!temp/SFP-2022-04-18_145205.jpg'
0 image files updated
2 image files unchanged
YES! Regex! I could NOT for the life of me remember the tool I needed to google for.
Usually writing it all out to post triggers something, but this time nothing. Thank you StarGeek!
Quote from: StarGeek on April 18, 2022, 05:56:58 PM
You can use regex to extract the ID.
exiftool -d %Y-%m-%d_%H%M%S%%-c.%%e '-FileName<${UserComment;m/ID=([^,]+),/;$_=$1;}-$CreateDate' file.jpg
Example output
C:\>exiftool -G1 -a -s -CreateDate -UserComment y:\!temp\Test3.jpg y:\!temp\Test4.jpg
======== y:/!temp/Test3.jpg
[ExifIFD] CreateDate : 2022:04:18 14:52:05
[ExifIFD] UserComment : MR=C.1,AD=3/10/2022,LD=38,BT=11,RD=36,LH=0,LI=22,BL=7959,BP=50%,BS=Ext,BD=37,BI=30,CF=Disabled,IR=Indoors,WL=850nm,EX=Centered,ID=TRIPOD,LO=001,MA=1B034C1A926E,SM=SUR,DD=FAP,DI=1,DV=OFF,DL=OFF,ND=FAP,NI=1,NV=OFF,NL=OFF
======== y:/!temp/Test4.jpg
[ExifIFD] CreateDate : 2022:04:18 14:52:05
[ExifIFD] UserComment : MR=C.1,AD=11/6/2020,LD=32,BT=12,RD=0,LH=0,LI=29,BL=5290,BP=50%,BS=Int,BD=0,BI=2,CF=Enabled,EX=Centered,ID=SFP,LO=005,MA=2818C978936E,SM=SUR,DD=FAP,DI=1,DV=OFF,DL=OFF,ND=FAP,NI=1,NV=OFF,NL=OFF
2 image files read
C:\>exiftool -d %Y-%m-%d_%H%M%S%%-c.%%e "-TestName<${UserComment;m/ID=([^,]+),/;$_=$1;}-$CreateDate" y:\!temp\Test3.jpg y:\!temp\Test4.jpg
'y:/!temp/Test3.jpg' --> 'y:/!temp/TRIPOD-2022-04-18_145205.jpg'
'y:/!temp/Test4.jpg' --> 'y:/!temp/SFP-2022-04-18_145205.jpg'
0 image files updated
2 image files unchanged
This work perfect after I switched the double quotes to single for linux
Quote from: ronoc on April 19, 2022, 08:07:39 AM
Quote from: StarGeek on April 18, 2022, 05:56:58 PM
You can use regex to extract the ID.
exiftool -d %Y-%m-%d_%H%M%S%%-c.%%e '-FileName<${UserComment;m/ID=([^,]+),/;$_=$1;}-$CreateDate' file.jpg
This work perfect after I switched the double quotes to single for linux
Yep, that's why the command line I first listed had them ;) I'm on Windows so my example had to use double.