LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script to sort image files (https://www.linuxquestions.org/questions/programming-9/bash-script-to-sort-image-files-487211/)

dtcs 09-26-2006 05:00 PM

Bash script to sort image files
 
I am trying to write a simple bash script or one line command to basically sort a bunch of .jpg files by date from `identify -verbose` command.
The reason I don't use `ls -l` command to parse date is because the date stamp is incorrect.

Here's what I have:
Code:

identify -verbose *.jpg | awk '/Date Time Original: 2005:02:13 / {print $4}'
How do I change this command to print the file name instead of date?
And how would I pass those files to be copied to other directory?

Thanks in advance.

konsolebox 09-26-2006 06:05 PM

hello dtcs. can you post the output of your command? tnx

dtcs 09-26-2006 06:31 PM

it just prints the same date for files that match the expression.
date is the 4th column in that line.

Now I am not that good with awk.
If I want to show the file name, one way of doing it is by calling another expression in awk like /^Image:/ but how do I do that only if first expression is True.

konsolebox 09-26-2006 07:49 PM

ok dtcs but i really need a sample output of 'identify -verbose *.jpg' so that i'll know how to modify the statement. can you post them pls? even just for the output of 1 jpeg file. i don't have the 'identify' command btw.

dtcs 09-26-2006 08:55 PM

identify is part of image magick
Code:

2005:02:13

konsolebox 09-26-2006 09:50 PM

try this command:
Code:

for a in *.jpg; do
    identify -verbose $a | grep "Date Time Original: 2005:02:13" >/dev/null && {
        echo "found $a"
        cp $a anydir/
    }
done



All times are GMT -5. The time now is 02:52 PM.