title: How to parse of EXIF time stamps with Bash script
body: <p>As a bash script rookie, detailed answers would be appreciated. :)</p>
  
  <p>I am trying to write a bash script that parses JPEG EXIF time stamps output from the exiv2 commmandline utility, which gives me typical output like:</p>
  
  <blockquote>
    <p>Image timestamp : 2010:07:27 17:38:52</p>
  </blockquote>
  
  <p>Is there a way to parse the time stamp so that its components, like year, month, day, hour, minute, second, go into respective variables?</p>
  
  <p>Would sed/gawk be the way to go? If so, how? Or is some other way better?</p>
  
  <p>This way, I can manipulate or mix and match them however I like.</p>
  
  <p>Here is the script I've got so far:</p>
  
  <pre><code>#!/bin/bash
  
  COUNT=0
  SKIPPED=0
  FILES=0 # number of files encountered
  
  # declare variables for time stamp
  
  YEAR=0
  MONTH=0
  DAY=0
  
  HOUR=0
  MINUTE=0
  SECOND=0
  
  for CURRENT_FILE in * # a for loop to go through all files in current directory
  do
      if [ -f "$CURRENT_FILE" ] # see if CURRENT_FILE is a file
      then
          FILETYPE=$(file -b --mime-type "$CURRENT_FILE") # get file type
          if [[ $FILETYPE == image/jpeg ]] # see if CURRENT_FILE's mime is image/jpeg
          then
              ((COUNT++))
              echo "Processing file $COUNT: $CURRENT_FILE"
              exiv2 "$CURRENT_FILE" | grep timestamp &gt;&gt; list
          else
              ((SKIPPED++))
              echo "Skipping file $CURRENT_FILE....."
          fi
          ((FILES++))
      fi
  done
  
  echo "Encountered $FILES files"
  echo "Processed $COUNT files"
  echo "Skipped $SKIPPED files"
  </code></pre>
  
  <p>Thanks!</p>