Created
October 31, 2011 13:41
-
-
Save atomicstack/1327510 to your computer and use it in GitHub Desktop.
Convert a single column list into an SQL IN statement, or alternatively a pipe-separated list which can be used with grep.
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 | |
export SEP_CHAR="" | |
export QUOTE_CHAR="" | |
test "$1" == "--grep" && export SEP_CHAR="|" | |
( test "$1" == "--sql" || test -z "$1" ) && export SEP_CHAR="," && export QUOTE_CHAR="'" | |
new_list=$( pbpaste | perl -e 'chomp(@lines = <STDIN>); print q{(} . join( $ENV{SEP_CHAR} => map { $ENV{QUOTE_CHAR} . $_ . $ENV{QUOTE_CHAR} } @lines ) . q{)}' ) | |
echo $new_list | pbcopy | |
echo "$new_list" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment