Renaming files

hi,

I have the following files as below.

reg_test_123232
reg_test_125654
reg_test_473843

How do I rename reg_test_123232 to abc_123232 and the rest of file by just keeping the numeric field ?

Please advise :slight_smile:

HI,
Use this code
for i in `ls *[0-9]*`
do
OUT=`echo $i | awk -F'
' '{print "abc_"$3}'`
mv $i ${OUT}
done

In sed it can be done in a better way but i am not able to get it...
Thanks
Raghuram

hi.. thanks. it works :slight_smile:
I will find out then.

With zsh:

autoload -U zmv
zmv 'reg_test_(*)' 'abc_$1'

Otherwise (if the files contain at least one record/line):

awk 'FNR==1{split(FILENAME,f,"_");print "mv", FILENAME," abc_" f[3]|"sh"}' reg_test*

Use nawk on Solaris.