Last active
December 18, 2015 15:39
-
-
Save teabot/5805764 to your computer and use it in GitHub Desktop.
Generated create table DDL from header rows of delimited files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
delim=$1 | |
for file in *.tsv | |
do | |
name=${file%.tsv} | |
columns=`head -n1 $file` | |
echo -n "CREATE TABLE $name (" | |
arr=$(echo $columns | tr $delim "\n") | |
first=1 | |
for column in $arr | |
do | |
if [ $first -eq 1 ] ; then nl="" ; pk=" primary key" ; nu="not null" ; else nl=","; pk="" ;nu="null" ; fi | |
echo $nl | |
echo -n " $column text $nu$pk" | |
first=0 | |
done | |
echo "" | |
echo ");" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment