#!/bin/bash
p=""
struct=""
i=0
for line in $(cat $1)
do
pre=$(echo $line | awk '{print $0}' | cut -c 1)
if [[ $pre == "\`" ]]; then
colum=$(echo $line | awk -F "\`" '{print $2}')
if [[ $i == 0 ]];then
p=$p"static const std::string TABLE_NAME=\""$colum"\";"
else
p=$p"\r\n"
struct=$struct"\n"
p=$p"static const std::string FLD_"$(echo $colum | cut -c2- | tr 'a-z' 'A-Z')"=\""$colum"\";"
struct=$struct"std::string str"$(echo $colum | sed 's/'F'/''/g' | sed 's/^\w\|\_\w/\U&/g' | sed 's/\_/''/g')";"
fi
i=$(( $i + 1 ))
fi
done
echo
echo -e $p
echo
echo -e $struct
echo
表格式
CREATE TABLE `t_a` (
`Fa` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
PRIMARY KEY (`Fa`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='';
//*******************************************************************************
//1去掉F
//2首字符大写
//3去掉_
echo "Fhello_o" | sed 's/'F'/''/g' | sed 's/^\w\|\_\w/\U&/g' | sed 's/\_/''/g'
//
#!/bin/bash
p=""
struct=""
i=0
maxlen=0
for line in $(cat $1)
do
pre=$(echo $line | awk '{print $0}' | cut -c 1)
if [[ $pre == "\`" ]]; then
colum=$(echo $line | awk -F "\`" '{print $2}')
if [[ $i == 0 ]];then
v=1
else
left=$(echo $colum | cut -c2- | tr 'a-z' 'A-Z')
len=${#left}
if [ $len -gt $maxlen ]; then
maxlen=$len
fi
fi
i=$(( $i + 1 ))
fi
done
i=0
for line1 in $(cat $1)
do
pre=$(echo $line1 | awk '{print $0}' | cut -c 1)
if [[ $pre == "\`" ]]; then
colum=$(echo $line1 | awk -F "\`" '{print $2}')
if [[ $i == 0 ]];then
text=$( printf "%-"$(( $maxlen-6))"s =" "" )
p=$p"static const std::string TABLE_NAME"$text"\""$colum"\";"
else
left=$(echo $colum | cut -c2- | tr 'a-z' 'A-Z')
text=$( printf "%-"$maxlen"s %s=" $left "" )
p=$p"\r\n"
struct=$struct"\n"
p=$p"static const std::string FLD_"$text"\""$colum"\";"
struct=$struct"std::string str"$(echo $colum | sed 's/'F'/''/g' | sed 's/^\w\|\_\w/\U&/g' | sed 's/\_/''/g')";"
fi
i=$(( $i + 1 ))
fi
done
echo
echo -e "$p"
echo
echo -e $struct
echo