LoginSignup
0
0

More than 5 years have passed since last update.

BQのテーブルをGCSにアップロードするshell

Last updated at Posted at 2018-01-10

UIから手動で実行するのは面倒だし、API使ってプログラム書くのも面倒だしと思って簡易なshellを作成。備忘録程度に。

#! /bin/bash

tables=`bq --project_id $1 ls $2 | perl -ane 'print $F[0] . "\n" if $.>2'`
for table in $tables
do
  bq --project_id $1 extract $2.$table gs://$3/tables/$table.csv
done

$1はproject id、$2はdataset、$3はbucket

削除する場合はbq --project_id $1 rm -f $2.tableを代わりに使う。

テーブルの行数を数えるときは、bq --project_id <project> show <dataset>.<table> | perl -ane 'print $F[6] . "\n" if $.==5'
1
をtabelsに代入してtotalを求める

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0