Shell script help needed

Christopher Browne cbbrowne-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Sun Sep 4 01:42:16 UTC 2011


On Sat, Sep 3, 2011 at 9:36 PM,  <phiscock-g851W1bGYuGnS0EtXVNi6w at public.gmane.org> wrote:
> Folks -
>
> I have a mass of files with names like crw_0858.tiff that I need to
> convert to black an white using the following command line.
>
> convert crw_0858.tiff -colorspace Gray output_0858.tiff
> convert crw_0859.tiff -colorspace Gray output_0859.tiff
>
> etc
>
> This is beyond my shell-scripting capabilities. Can anyone suggest a
> simple shell script that can do this?
>
> Error checking is not required since I'm the only one to run this thing,
> and I do it manually.

I'd use "cut", liberally...

for i in crw_*.tiff; do
bname=`echo $i | cut -d _ -f 2 | cut -d . -f 1`
convert crw_${bname}.tiff -colorspace Gray output_${bname}.tiff
done

The idea, here, is to chop off the prefix and suffix; bname will
contain values like "0858" and "0859".
-- 
When confronted by a difficult problem, solve it by reducing it to the
question, "How would the Lone Ranger handle this?"
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list