java shell template多个字段模板生成

 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驼峰正则表达式)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值