Skip to content

Instantly share code, notes, and snippets.

@teabot
Last active December 18, 2015 15:39

Revisions

  1. teabot renamed this gist Jun 18, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. teabot renamed this gist Jun 18, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. teabot revised this gist Jun 18, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions header2ddl
    Original file line number Diff line number Diff line change
    @@ -10,9 +10,9 @@ do
    first=1
    for column in $arr
    do
    if [ $first -eq 1 ] ; then nl="" ; else nl="," ; fi
    if [ $first -eq 1 ] ; then nl="" ; pk=" primary key" ; nu="not null" ; else nl=","; pk="" ;nu="null" ; fi
    echo $nl
    echo -n " $column text null"
    echo -n " $column text $nu$pk"
    first=0
    done
    echo ""
  4. teabot revised this gist Jun 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion header2ddl
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ for file in *.tsv
    do
    name=${file%.tsv}
    columns=`head -n1 $file`
    echo -n "CREATE TABLE $name AS ("
    echo -n "CREATE TABLE $name ("
    arr=$(echo $columns | tr $delim "\n")
    first=1
    for column in $arr
  5. teabot created this gist Jun 18, 2013.
    20 changes: 20 additions & 0 deletions header2ddl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash

    delim=$1
    for file in *.tsv
    do
    name=${file%.tsv}
    columns=`head -n1 $file`
    echo -n "CREATE TABLE $name AS ("
    arr=$(echo $columns | tr $delim "\n")
    first=1
    for column in $arr
    do
    if [ $first -eq 1 ] ; then nl="" ; else nl="," ; fi
    echo $nl
    echo -n " $column text null"
    first=0
    done
    echo ""
    echo ");"
    done