hello.sh
#!/bin/bash
tt=$IFS
echo $tt
rm -rf result
mkdir result
fileList=`ls template`;
fileList=`echo $fileList`;
for fileName in $fileList;
do
echo $fileName"==============================";
cat field.txt | while read line
do
tt=$IFS
IFS=
cat template/$fileName | while read -r line2
do
lineU=`echo $line | tr 'a-z' 'A-Z'`
lineTuoFeng=`echo $line |sed -r 's/([a-z]+)_([a-z])([a-z]+)/\1\U\2\L\3/'`
content=`echo $line2 | sed 's/xx/'$line'/g' | sed 's/XX/'$lineU'/g' |sed 's/xX/'$lineTuoFeng'/g'`
echo $content
echo $content >> result/$fileName.txt
done
done
echo $fileName"============================== one line have a bug * should change";
content=`cat result/$fileName.txt | xargs > result/line_$fileName.txt`
done
IFS=$tt
field.txt
wdsx
field2
field_hello
template/hello.txt
<if test="xX != null and xX !=''">
XX = #{xX}
</if>
template/hello2.txt
/** XX xx*/
private String xX;
执行hello.sh
得到结果
hello2.txt==============================
/** WDSX wdsx*/
private String wdsx;
/** FIELD2 field2*/
private String field2;
/** FIELD_HELLO field_hello*/
private String fieldHello;
hello2.txt============================== one line have a bug * should change
hello.txt==============================
<if test="wdsx != null and wdsx !=''">
WDSX = #{wdsx}
</if>
<if test="field2 != null and field2 !=''">
FIELD2 = #{field2}
</if>
<if test="fieldHello != null and fieldHello !=''">
FIELD_HELLO = #{fieldHello}
</if>
hello.txt============================== one line have a bug * should change
文件下载链接
https://download.csdn.net/download/tanghuan0827/13695933
shell脚本 执行hello.sh脚本就可以了。有点小bug,对于多行的转换
sh hello.sh
结果在result文件夹里面
参考链接:
https://cloud.tencent.com/developer/ask/91789 (bash读不出前导空格)
https://qastack.cn/unix/196239/convert-underscore-to-pascalcase-ie-uppercamelcase (sed驼峰正则表达式)