As a bash script rookie, detailed answers would be appreciated. :)
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:
Image timestamp : 2010:07:27 17:38:52
Is there a way to parse the time stamp so that its components, like year, month, day, hour, minute, second, go into respective variables?
Would sed/gawk be the way to go? If so, how? Or is some other way better?
This way, I can manipulate or mix and match them however I like.
Here is the script I've got so far:
#!/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 >> list
else
((SKIPPED++))
echo "Skipping file $CURRENT_FILE....."
fi
((FILES++))
fi
done
echo "Encountered $FILES files"
echo "Processed $COUNT files"
echo "Skipped $SKIPPED files"
Thanks!