Skip to content

Instantly share code, notes, and snippets.

@itochu0523
Last active October 24, 2016 13:20
Show Gist options
  • Save itochu0523/791f1443a124d1e161dede0e913f18bf to your computer and use it in GitHub Desktop.
Save itochu0523/791f1443a124d1e161dede0e913f18bf to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# td command option
# -d : database name
# -w : waiting
# --output : output file name to local
# -f : file format
# -c : add column name (top line)
mode=$1
while read table
do
echo "$table"
if [ $mode = "add_header" ]; then
td query -d sample_datasets 'select count(1) from $table' -w -T presto --output test.csv -f csv -c
mv test.csv test_tmp.csv
cat '$table'.csv test_tmp.csv >> '$table'.csv
rm test_tmp.csv
else
td query -d sample_datasets 'select count(1) from $table' -w -T presto --output test.csv -f csv
mv test.csv test_tmp.csv
cat test_tmp.csv > '$table'.csv
rm test_tmp.csv
fi
done < table_list.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment