#!/bin/bash
# 根据建表语句,将字段由驼峰命名(camelCase)转换为下划线命名(snake_case)
# 连续的大写字母只在第一个字段前添加下划线
flag=" "
grep -Ev "CREATE TABLE|PRIMARY KEY|ENGINE=InnoDB" tmpa|awk '{print $1,$NF}'|sed "s/[\'\`,]//g"|while read line
do
column=$(echo ${line}|awk '{print $1}')
name_cn=$(echo ${line}|awk '{print $2}')
columns_snake_case=$(echo "${column}" | sed 's/\([A-Z]\)\([A-Z]*\)/_\L\1\2/g' | sed 's/^_//'|sed 's/__/_/g')
printf " %s%-50s as %-50s -- %s\n" "${flag}" "${column}" "${columns_snake_case}" "${name_cn}"
flag=","
done