shell脚本从文件中读取数据按照特定的格式写文件

shell脚本从文件中读取数据按照特定的格式写文件

2023年8月2日发(作者:)

shell脚本从⽂件中读取数据按照特定的格式写⽂件具体脚本如下:#!/bin/bashsetParams(){sed -i '$d' $3echo $2 | tr -d '[]'|awk -F, '{for(i=1;i<=NF;i++)if(match($i,/ENDTIME/)||match($i,/STARTTIME/)){if(length(substr($i,index($i,":")))==10){sub(/:.*/,",(0,0)",$i);print $i;}else if(length(substr($i,index($i,":")))==13){sub(/:.*/,",(0,0,-1)",$i);print $i}else if(length(substr($i,index($i,":")))==7){sub(/:.*/,",(0)",$i);print $i}}else{sub(/:/,",",$i);print $i}

}' | awk 'BEGIN{FS="r"print " public static final HashMap '"$1"' = new HashMap{{"}

{for(j=1;j<=NF;j++)print " put("$j");"}END{ print " }};" }' >> $3sed -i '$a}' $3}addParamInfile(){mapVar=$(sed -n '/'"$1"'[ =]/p' $2)echo "=========start exec addParamInfile========="if [[ -z $mapVar ]]; thenecho "+++++start insert paramters ${1}."setParams $1 $3 $2cat $2echo "+++++end insert paramters ${1}."elseecho "$1 already exists."fiecho "=========end exec addParamInfile========="}createMapFile(){echo "=========start exec createMapFile========="mapFileDirPath=${1}"/"${2}echo "create new folder $mapFileDirPath ..."mkdir $mapFileDirPathfullFileName=${mapFileDirPath}"/"${3}".java"echo "create new file $fullFileName ..."echo -e "public static $3{n}">$fullFileNamecat $fullFileNameecho "=========end exec createMapFile========="}printTitle(){echoecho "###################################################################################"echo "# #"echo "# The Time Of Running Scrpit:$(date) #"echo "# #"echo "###################################################################################"echo}addUrl(){urlnametemp=$(sed -n '/'"${2}"'[ =]/p' $1 | cut -d = -f 2 | tr -d '"')urlPathinfile=$(echo ${urlnametemp%;*})echo "========Insert Or Modify urlPath information=========="echo "Modify $1"if [[ -z $urlPathinfile ]]; thensed -i '/}/i public static final '"$2"'="'"$3"'";' $1echo "Finish to insert $2 ."elseif [[ "$urlPathinfile" == "$3" ]]; thenecho "$urlPathinfile already exists."elseecho "Modify $urlPathinfile ..."sed -i '/'"${2}"'[ =]/s#'"$urlPathinfile"'#'"$3"'#g' $1fifi}addParameters(){echo "========Insert Or Modify urlParameters information=========="#api参数存储⽂件名称fileName=$(echo $2|tr [a-z] [A-Z])"_inforMap"#api所属看板缩写⽬录名称,全路径mapFileDirPath=$(find $1 -iname $2)echo "The folder is $mapFileDirPath"#判断⽬录是否存在;存在时,进⾏下⼀步处理;不存在时,新建⽬录、⽂件if [[ -d $mapFileDirPath ]]; thenecho "$mapFileDirPath already exists."fullFileName=$(find $1 -iname ${fileName}"*")echo "⽬录⽂件已存在,插⼊新的api参数常量."addParamInfile $urlName $fullFileName $urlParaelseecho "⽬录⽂件不存在,新建⽬录⽂件."createMapFile $1 $2 $fileNameecho "新增api的参数常量"addParamInfile $3 $fullFileName $4fi}if [[ -z $1 ]]; thenecho "Usage: bash 数据读取⽂件"elif [[ -f $1 ]]; thenprintTitle>>Dir=$(find . -iname "mapinfo")urlFileName=$(find . -iname "urlmap*")count=1while read urlInfor

doechoecho "#######################执⾏第$count次########################"#api的名称urlName=$(echo $urlInfor|awk 'BEGIN{FS="[ t]"} {print $2}')#api的url参数urlPara=$(echo $urlInfor|awk 'BEGIN{FS="[ t]"} {print $4}')#api所属看板缩写,即⽬录名称mapFileDir=$(echo $urlInfor|awk 'BEGIN{FS="[ t]"} {print $1}')#api的urlurlPath=$(echo $urlInfor|awk 'BEGIN{FS="[ t]"} {print $3}')#新增api的urladdUrl $urlFileName $urlName $urlPath#新增api的⼊参addParameters $mapDir $mapFileDir $urlName $urlParalet count=$count+1done<$1>>eecho "$1 is not a file."fi

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1690920538a463815.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信