bash scripting help

Stefan Krah sfk1 at bigfoot.com
Thu Mar 24 06:54:27 PST 2005


* Sébastien Maerten <maerten.sebastien at laposte.net> wrote:
> 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 ?

[GNU find]:

find . -name '*.[Jj][Pp][Gg]' -print0 | xargs -0 jhead \
        | awk '/^File name/{printf "NAME: %s\t", $4} \
               /^File size/{printf "SIZE: %s\t", $4} \
               /^Date\/Time/{printf "DATE: %s %s\t", $3, $4} \
               /^Resolution/{printf "RESO: %s x %s\n", $3, $5}'


Untested, I don't know the exact output of jhead. And find will of course
descend further unless you prevent that with -maxdepth or similar.


Stefan Krah



More information about the lfs-chat mailing list