On 10/17/2007 12:13 AM, H.S. wrote:
[...] BTW, for some reason, the following does not work: $> for f in `find E/ -name "*.[Jj][Pp][Gg]"`; do echo "$f"; done The output of the above command has a new line before each parenthesis.
You might need to change bash's internal field separator (IFS) for that to work:
OLDIFS="$IFS" IFS=$'\n' for fn in `find E.DIR/ -name "*.[Jj][Pp][Gg]"` do nn2=`echo -n "$fn" | sed -e 's/ *(\([0-9]\+\))/\1/'` mv "$fn" "$nn2" done IFS="$OLDIFS" And here's another way using arrays: OLDIFS="$IFS" IFS=$'\n' find E.DIR/ -name "*.[Jj][Pp][Gg]" > E.DIR/f1 sed -e 's/ *(\([0-9]\+\))/\1/' < E.DIR/f1 > E.DIR/f2 lines=(`cat E.DIR/f1`) lines2=(`cat E.DIR/f2`) for ((i = 0; i < ${#lines[*]}; i++)) do mv -v "${lines[i]}" "${lines2[i]}" done IFS="$OLDIFS" :-D