- 论坛徽章:
- 0
|
/home/test/rem路径下有999个文件,文件名的格式:filename_YYYYMMDD_序列号((001-999).dat,例如:filename_20140108_089.dat,现在想把这些文件名改名,文件名为:file_TODAY(当前日期_序列号(从500开始,到达999之后从001开始).dat,例如_089为_589,099为_599.
现在我写脚本如下,但效率不高,求各位大神优化~
[ -d /home/test/rem ] && : || mkdir -p /home/test/rem
cd /home/test/rem
rm -rf ./*
for i in `seq -f %03g 1 999`;do
touch testfile_20140109_$i.dat
done
for j in `ls testfile*`;do
b=`echo $j | awk -F '[_.]' '{OFS="_";$1="test";"date +%Y%m%d"|getline $2;if($3 < 500){$3 = $3 + 500} else {$3 = $3 - 499};if($3 < 10){$3="00"$3} else if ($3 < 100){$3="0"$3} else{$3=$3};print $1,$2,$3"."$4}'`
mv $j $b
done
time sh rem.sh
real 1m31.585s
user 0m13.889s
sys 0m43.519s |
|