linux shell批量重名了java 类

liweihui 2016-12-28

linux shell批量重名了java 类

所以的单元测试类,名称后面添加Test

即把Student.java ,改为StudentTest.java

#!/bin/bash
for i in `find /Users/whuanghkl/work/shop/src/test/java/com/ -type f -name "*.java"| sed 's#\.java$##'`;do
        fileSimpleName=`echo $i|sed 's#^.*/##'` #去掉目录
        suffix22=`echo $fileSimpleName |sed '/Test$/d'` #判断文件名称是否以Test结尾
        if [ !  -s $suffix22 ]; then
                echo "aa"
        echo $suffix22
        echo "fileSimpleName:$fileSimpleName" #Student ,没有.java
        echo $i.java
        sed -i "" "s/$fileSimpleName/${fileSimpleName}Test/g" $i.java
        mv  $i.java ${i}Test.java
        fi
done

注意:

(1)mac中 sed -i 后面要增加空字符串

(2)mac中,xargs的用法也不太一样

find . -iname *something* | xargs -I {} mv {} ../Other/Location

 find ./ -type f -iname "*.json"|sed 's/json$//' |xargs -I {} mv {}json {}xml

相关推荐