linux shell batches renamed java classes

linux shell batches renamed java classes

So the unit test class, add Test after the name

That is, change Student.java to 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#^.*/##'` #Remove directory
        suffix22=`echo $fileSimpleName |sed '/Test$/d'` #Determine whether the file name ends with 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
        be
done

 

Notice:

(1) An empty string should be added after sed -i in mac

(2) In mac, the usage of xargs is not the same

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

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326361352&siteId=291194637