Hi Ed,

> does this assume that the current folder contains only the files to be
> renamed?

Indeed it does.  I was aiming to show that for simple tasks like this, 
a modern shell makes things easy enough that scripts become overkill.

> Also, how does one add padding zeros?

You can just add in a printf to go, e.g., from a padded 001 to 360:

c=1 && for f in * ; do echo mv $f CD267A_3_pk_1_`printf "%03d" "$c"`.img ; 
c=$(($c+1)) ; done

Or a more specific set of images:

c=1 && for f in CD267A_3_pk_1_*.img ; do echo mv $f CD267A_3_pk_1_`printf 
"%03d" "$c"`.img ; c=$(($c+1)) ; done

Or an even more specific set of images:

c=1 && for f in CD267A_3_pk_1_{1081..1440}.img ; do echo mv $f 
CD267A_3_pk_1_`printf "%03d" "$c"`.img ; c=$(($c+1)) ; done 

I guess once it gets complex enough then you might as well go down James'
path and create a generalized script that can be used in many cases, but
it's definitely more work to write the generalized script than to toss off
one liners.

-ben

--
| Ben Eisenbraun                              | Software Sysadmin      |
| SBGrid Consortium                           | http://sbgrid.org      |
| Harvard Medical School                      | http://hms.harvard.edu |

Reply via email to