You are not logged in.
I'm trying to develop a shell script to sort(?) images by resolution, and I'm stuck on something. This is what I have:
#!/bin/bash
echo "What resolution would you like to select? ex. 1280x800"
read RES
echo "The resolution you have selected is $res"
echo "Removing Spaces from filenames"
rename -v 's/\ /\_/g' *
echo "Making list of files..."
ls *.jpg > filelist.txt
echo "Identifying images that match desired resolution..."
identify $(cat filelist.txt) > modlist.txt
echo "Grepping..."
grep $RES modlist.txt > final.txt
And the problem starts there. In order to move the desired images, I need to remove the extraneous information from the lines, leaving only the file name. I've done quite a bit of googling about this, and can't find a sed or awk or anything to fit my needs. Is this possible?
Basically, I need to modify this:
autumn-sky.jpg[94] JPEG 1440x900 1440x900+0+0 8-bit DirectClass 1.212MB 0.010u 0:00.000
into this:
autumn-sky.jpg
Thanks in advance...
Looking for the author of Haxial KDX.
Email me: xen0systems [at] gmail.com
Offline
edit - nevermind. I misread your post
Last edited by daneel971 (2010-01-16 15:37:14)
Offline
cut -d "[" -f1 works for me. Is that what you are looking for?
$ echo "autumn-sky.jpg[94] JPEG 1440x900 1440x900+0+0 8-bit DirectClass 1.212MB 0.010u 0:00.000" | cut -d "[" -f1
autumn-sky.jpg
Offline
I guess you really mean filter by resolution, rather than sort, am I right? The cut example given by linkmaster03 is okay but it won't work if any of the files have a [ in the filename. You could try doing it by sed, this way works for your example:
sed -r 's/([^.]*\..{3,4})\[.*/\1/'
If this doesn't quite work for some of the lines then you should be able to modify it, the basic idea is there anyway.
Offline
Thanks! I don't know sed and awk yet ...Yet....
Looking for the author of Haxial KDX.
Email me: xen0systems [at] gmail.com
Offline
Are there some magical spaces that aren't spaces in filenames that I should know about??? If there aren't, then why are some spaces remaning in filenames after I pass
rename -v 's/\ /\_/g' *
. It's never failed me before, or is that a fluke too....:?
oh, and the Code so far:
#!/bin/bash
echo "What resolution would you like to select? ex. 1280x800"
read RES
echo "The resolution you have selected is $res"
echo "Removing Spaces from filenames"
rename -v 's/\ /\_/g' *
echo "Making list of files..."
ls *.jpg > filelist.txt
echo "Identifying images that match desired resolution..."
identify $(cat filelist.txt) > modlist.txt
echo "Grepping..."
grep $RES modlist.txt > final.txt
cat final.txt | sed -r 's/([^.]*\..{3,4})\[.*/\1/' > final2.txt
mkdir RezzedImages
mv $(cat final2.txt) RezzedImages
rm -rf *.txt
echo "Done!"
Last edited by xen0blade (2010-01-16 17:36:19)
Looking for the author of Haxial KDX.
Email me: xen0systems [at] gmail.com
Offline
Is rename even supposed to take a regular expression like that? Also you seem to have the regex enclosed in backticks, which will cause bash to try and do command substitution.
Anyway, does this do what you need?
rename ' ' _ *
Edit: Also, if I remember correctly giving a command a very long list of arguments will sometimes fail to work if the list is too long. For situations like that, you ought to use xargs. For example, I think you should probably change
identify $(cat filelist.txt) > modlist.txt
to
xargs identify < filelist.txt > modlist.txt
So that it won't break if filelist.txt contains very many entries. I might be wrong though.
Edit 2: Oh no, according to Wikipedia you can pass arbitrarily long argument lists since kernel 2.6.23. We live and learn, don't we?
Edit 3: Regarding the rename problem, see this relevant forum topic: http://bbs.archlinux.org/viewtopic.php?id=85128
Last edited by Bralkein (2010-01-16 19:24:40)
Offline
feh is a pretty nice cli image viewer that can be used for all kinds of stuff. Being able to specify the output format is pretty handy if you want to maintain filename spaces.
#!/bin/bash
echo "What resolution would you like to select? ex. 1280x800"
read RES
IFS='\n'
mkdir rezzed
for img in $(feh -L "%wx%h %n" *.jpg | grep $RES | cut -d ' ' -f 2-); do
mv -v "$img" rezzed
done
Last edited by scj (2010-01-17 00:49:33)
Offline
Awesome....Absolute geniuses...whatever would I do without you people?
Looking for the author of Haxial KDX.
Email me: xen0systems [at] gmail.com
Offline
Still debugging (A lack of time really impedes this project o' mine...)...
Looking for the author of Haxial KDX.
Email me: xen0systems [at] gmail.com
Offline