[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ProgSoc] Looping over filenames in bash



On Fri, 14 Dec 2007, Robert Howard wrote:
> PS: I also ended up running into ${ii/.jpg/.small.png} and friends, thanks
> to the above little snippet, as sort of highly-impaired regex of sorts.

 I sometimes use the ${} stuff (it's pretty powerful, nearly
 as good as GWBasic's substring function), but usually resort
 to one of two other options to solve the original problem.

 mkdir small
 for i in *jpg
    do
        convert -sample 200 $i small/$i
    done

 This usually works for me because I want to do a bundle
 of them, I want to compare old with new file quality (visual)
 and I'm usually aiming at getting the file set to a specific size
 (CD, memory stick, etc) and this is easier to assess in a subdir
 rather than the same dir.

 Sometimes I use basename to rename files as you were doing
 with sed in your original script.

 for i in *jpg
   do
      convert -sample 200 $i `basename $i .jpg`-small.jpg
   done

 Faffing around to handle embedded spaces in the filename is
 left as an exercise for the reader.

 Jedd.

-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.