mr2pat

本文介绍了一个复杂的Shell脚本示例,该脚本用于处理文本文件中的数据,包括条件判断、循环处理、文件操作等关键功能。通过对特定文件格式的解析,实现对不同类型的代码片段进行分类、提取和重新组织。
#!/bin/bash


tmp=wywtemp.txt


files=`awk -F ':' '{print $1}' $tmp`


ofc_projs=(aaa bbb ccc)




for file in $files;do


err=0
ask=0


eval $(echo $file | awk -F '/' '{
if($1!="product"||$2!="cr")
{
print("err=1")
}
if($3=="drv")
{
if($4=="ofc")
{
print("ask=1")
}
else
{
print("err=1")
}
}


if($1=="tar.c") 
{
print("dest=dest.c")
}
}')


if [[ $err -ne 0 ]];then
echo "error happens: errNo:"$err
exit
fi


if [[ $ask -ne 0 ]];then
if [[ $ask -eq 1 ]];then
echo "what ofc(s)?"
for(( i=0;i<${#ofc_projs[@]};i++)) do
echo $i" : "${ofc_projs[$i]}
done
elif [[ $ask -eq 2 ]]; then
echo "what sfu(s)?"
fi


echo "give me your answer(such as 012):"
read
choices=`echo $REPLY | grep -o .`
for dgt in $choices;do
dest=$patch/projects/${ofc_projs[$dgt]}/code/${ofc_projs[$dgt]}.c
done
echo $dest
fi



funcs=`awk -F ':' '$1=="'$file'" {print $2}' $tmp`


awk '$0~/#include/ {print}' $file > $dest
awk -F '=' '$0~/^ *[0-z_]+ *(\*+|&|\[\])? *[0-z_]+ *=.*/ {print "extern "$1";"}' $file >> $dest
awk '$0~/^ *extern *.*/ {print}' $file >> $dest
for func in $funcs;do
startlines=`awk '\$0~/^ *[0-z_]+ *(\*+|&|\[\])? *'$func' *\(.*\) *$/ {print NR}' $file`


if [[ ${#startlines} -ge 1 ]] ;then
nr=${startlines[0]}


echo $dest


awk 'NR=='$nr', $0~/^\}/ {print $0}' $file >> $dest
fi
done




done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值