Imagemagic script

Associate
Joined
1 Aug 2003
Posts
1,053
I was trying to write a script to mogrify some files but it seems to be crapping up on me, it's reached the point where I'm not sure what's going on any more. I'm getting the ' at the end of the lines but not the ' at the beginning of addresses. I'm sure it's something simple - thanks.

Any advice would be greatfully received.

rm /root/currentjpegs.txt
updatedb
locate *.j* > /root/currentjpegs.txt
locate *.J* >> /root/currentjpegs.txt
grep /usr/data/Projects/Projects\ 200 currentjpegs.txt > jpegs.txt
grep -iv therm jpegs.txt > therm.txt
sed -i 's/\/usr/mogrify\ -quality\ 75\ \''/usr/g' /root/therm.txt
sed -i 's/$/'\''/g' /root/therm.txt
 
Last edited:
That's pretty much what I'm after. The final command that I'd written, (sed -i 's/$/'\''/g' /root/therm.txt) worked perfectly, it was the one that added the mogrify command and the preceeding ' that wasn't working.

Your command didn't seem to work, I'm not used to the concatenating of commands like that, I too am very rusty in sed but I always separated out my commands, it made the commands longer and some would argue messier but it's a sign of how often I make mistakes as it makes them easier to track down ;)

sed -i 's/\/usr/mogrify\ -quality\ 75\ \''/usr/g' /root/therm.txt

Definitely adds the required mogrify command, but when I modify it to

sed -i 's/\/usr/mogrify\ -quality\ 75\ \'\/usr/g' /root/therm.txt


It doesn't know what I mean, which is odd because the first instance looks wrong to me but is the one it understands.
 
Last edited:
Well.... clearly I'm exceptionally rusty with sed as I didn't realise this...

In order to shove in an ' it's not just a simple matter of \' you have to type '\' which seems odd but it works.

sed -i 's/\/usr/mogrify\ -quality\ 75\ '\''\/usr/g' /root/therm.txt

What's even more odd is that I seemed to know that when I wrote the command to input the tailing '... clearly more coffee is needed.

I don't suppose you can offer advice with the advance of the script. I will need to add a check to make sure that it doesn't endlessly try to recompress the same images if rerun. My plan is to insert a line prior to:

grep /usr/data/Projects/Projects\ 200 currentjpegs.txt > jpegs.txt

That tells it to remove all instances that appear in both currentjpegs.txt and jpegs.txt. The way that I would have thought it would be done is:

comm -3 /root/currentjpegs.txt /root/jpegs.txt

I can see how it seems messy to have all these text files kicking about, but I want them there so that they can be read and reviewed if necessary.
 
Back
Top Bottom