Created
February 6, 2012 18:15
-
-
Save spara/1753818 to your computer and use it in GitHub Desktop.
make sql script for campus dropout rate
This file contains hidden or 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
| # 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