日期:2014-05-16  浏览次数:20758 次

用awk的一个批量改名问题
我这边有大量的文件,格式均为2012XXXXXXXX-XXXXXX-bXXXXXX.dat的文件,我要做的是将这些文件名改名为bXXXXXXXX.dat,批量哦,请问这个脚本要怎么写,求提示啊,文件模板:201204010000-000000-b044831.dat

------解决方案--------------------
PHP code
[User:root Time:18:33:38 Path:/home/liangdong/shell]$ ./test.sh   
mv: `test.sh' and `test.sh' are the same file
[User:root Time:18:33:39 Path:/home/liangdong/shell]$ ll
total 4
-rw-r--r--. 1 root      root        0 May 28 18:30 b044831.dat
-rw-r--r--. 1 root      root        0 May 28 18:30 b044832.dat
-rw-r--r--. 1 root      root        0 May 28 18:30 b044833.dat
-rwxr--r--. 1 liangdong liangdong 125 May 28 18:33 test.sh
[User:root Time:18:33:40 Path:/home/liangdong/shell]$ cat test.sh 
#!/bin/sh

ls -1 | while read name; do
        new_name=`echo $name | sed -r 's/^.*-.*-(.*\.dat)$/\1/g'`;
        mv $name $new_name;
done