bash scripting help

Sébastien Maerten maerten.sebastien at laposte.net
Thu Mar 24 01:19:21 PST 2005


Good morning -chat

Since my {scripting,basic utils} skills are *really* low, I'd like to 
ask you for some help.

The context: I'm trying to sort a directory containing around 10 000 
jpeg files (20 G). These files are pictures from a digital camera, many 
files have been copied/renamed and many others have been 
modified/renamed. I want to remove duplicates and modified files, while 
keeping original pictures.

The details: In order to sort files, I need some information about them, 
fortunately I can get this information from exif data that is stored in 
the files. Before anything else, I need to collect data for each file, 
for that I use a utility called jhead. Here is an example of what gives 
jhead :

JPG_Files > jhead 2005_0101_032039.jpg
File name    : 2005_0101_032039.jpg
File size    : 2377332 bytes
File date    : 2005:01:01 03:20:42
Camera make  : FUJIFILM
Camera model : FinePix S602 ZOOM
Date/Time    : 2005:01:01 03:20:39
Resolution   : 2832 x 2128
Flash used   : Yes (auto, red eye reduction mode)
Focal length :  7.8mm  (35mm equivalent: 37mm)
CCD width    : 7.65mm
Exposure time: 0.017 s  (1/60)
Aperture     : f/2.8
ISO equiv.   : 200
Whitebalance : Auto
Metering Mode: matrix
Exposure     : program (auto)

I need to store the following information in variables: file name, file 
size, date/time, camera model, resolution. I'm doing it this way :

for FILE in *.{jpg,JPG} ; do
     jhead $FILE > temp
     EXIF_NAME=`cat temp | grep "File name"  | cut -f 7 -d ' '`
     EXIF_SIZE=`cat temp | grep "File size"  | cut -f 7 -d ' '`
     EXIF_DATE=`cat temp | grep "Date/Time"  | cut -f 6,7 -d ' '`
     EXIF_RESO=`cat temp | grep "Resolution" | cut -f 5,7 -d ' '`
     printf "NAME: %s\tSIZE: %s\tDATE: %s %s\tRESO: %s x %s\n" 
$EXIF_NAME $EXIF_SIZE $EXIF_DATE $EXIF_RESO
     rm temp
     echo ""
done

The problem: this is really long since there are many files (38 
minutes). I guess it comes from the temp file writing / reading, but my 
knowledge is to small to figure a better way to get the information I 
need. Any ideas on how to parse the output of jhead in one pass ?

Any comment is welcome.



More information about the lfs-chat mailing list