Skip to content

Instantly share code, notes, and snippets.

@spara
Created February 6, 2012 18:15
Show Gist options
  • Select an option

  • Save spara/1753818 to your computer and use it in GitHub Desktop.

Select an option

Save spara/1753818 to your computer and use it in GitHub Desktop.
make sql script for campus dropout rate
# Make a sql script to create a table with only the dropout rate
# column using sed
#
$ tr -s ',' '\n' < campus_header | sed -n '2~3p' > campus_dropout_rate.sql
# grab the first n items in a file
$ wc -l campus_dropout_rate.sql
$ head -n 21 campus_dropout_rate.sql > tmp
# add the numeric type definition
$ sed 's/,$/ numeric,/g' tmp > first
# grab the last n items in a file
$ tr -s ',' '\n' < campus_header | tail -n 9 > tmp
# add the varchar type definition
$ sed 's/,$/ varchar,/g' tmp > last
# merge the two files
cat first last > campus_dropout_rate.sql
# add CREATE TABLE and closing parentheses
$ sed '1s/^/CREATE TABLE campus_dropout_rate( /' campus_dropout_rate.sql > tmp
$ sed '$s/,$/);/' tmp > campus_dropout_rate.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment