Skip to content

Instantly share code, notes, and snippets.

@h2ero
Last active December 20, 2015 19:09
Show Gist options
  • Save h2ero/6181141 to your computer and use it in GitHub Desktop.
Save h2ero/6181141 to your computer and use it in GitHub Desktop.
#! /bin/sh
# awk export mysql table info with markdown table
awk '
BEGIN{
}
{
if($0~/CREATE/){
gsub("`", "", $6)
print "### "$6
print "\n"
print "|字段名|类型|注释|"
print "|--------|---------|------------|"
}else{
if($0 ~ /^)/){
print "\n"
}
}
if($0 ~ /^[ ]+`/){
# print $0;
gsub("`", "", $0)
if($(NF-1) ~/COMMENT/){
sub(/,$/, "", $NF)
print "| "$1" | " $2" | " $NF "|"
}else{
print "| "$1" | " $2" | |"
}
}
}
END{
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment