Y1=`grep "^%%BoundingBox:" file1.eps | sed -e 's/^.*: *\([0-9]*\) *\([0-9]*\) *\([0-9]*\) *\([0-9]*\)/\2/'` Y2=`grep "^%%BoundingBox:" file1.eps | sed -e 's/^.*: *\([0-9]*\) *\([0-9]*\) *\([0-9]*\) *\([0-9]*\)/\4/'` for i in File[a-z].eps; do sed -i -e "s/^%%BoundingBox: *\([0-9]*\) *\([0-9]*\) *\([0-9]*\) *\([0-9]*\)/%%BoundingBox \1 $Y1 \3 $Y2/" $i; done