Looking for some help in renaming files using a shell script.
Suppose I have a directory which contains several files, some of which are *.dat
files. If there are 7 *.dat
files, I would like to rename all 7 *.dat
files to *.01
, *.02
, ... *.07
Here is what I have thus far:
ls -l *.dat $*| awk `
NF == 9 && /^-/{ #can someone explain this? this seems to loop through $
++filenum #increments to count number of *.dat files
print filenum, "\t", $9 #prints filenumber and current *.dat filename
newfile= $9 ".0" filenum #produces *.dat.01, but want *.01, *.02, etc
mv $9 $newfile # seems to do nothing, why?
}`
Any help is greatly appreciated!