I have some thousands of files in a folder and i need to change those file names without opening the file (no need to change anything in the file content, need to change the file name only). The filenames are as follows:
For other calculation, i need to take these files one by one and do the calculations. But these files are arranged in the following manner (OS-Linux):
Myfile_name.10_parameter
Myfile_name.11_parameter
Myfile_name.12_parameter
.
.
.
Myfile_name.100_parameter
Myfile_name.101_parameter
Myfile_name.102_parameter
.
.
.
Myfile_name.1000_parameter
Myfile_name.1001_parameter
Myfile_name.1002_parameter
.
.
.
.
.
Myfile_name.1_parameter
Myfile_name.20_parameter
Myfile_name.21_parameter ...so on and so forth...
for FILE in * # or whatever you want to select the files
do
EXT=${FILE##*.}
N=${EXT%_*}
END=${EXT#$N}
NEWNAME="${FILE%$EXT}$(printf '%04d\n' $N)$END"
echo "FILE=$FILE - NEWNAME=$NEWNAME"
# mv "$FILE" "$NEWNAME" # Uncomment this line to really rename files
done
for FILE in *_parameter
do
NEW=`echo $FILE |awk -F[._] '{printf "%s_%s.%04d_%s",$1,$2,$3,$4}' `
# mv "$FILE" "$NEW" # Uncomment this line to really rename files
done