Skip to content

Instantly share code, notes, and snippets.

@justinnaldzin
Created February 26, 2019 23:24
Show Gist options
  • Save justinnaldzin/721dc6924f2d428a8f886b2a099cd758 to your computer and use it in GitHub Desktop.
Save justinnaldzin/721dc6924f2d428a8f886b2a099cd758 to your computer and use it in GitHub Desktop.
Delete all tables matching a grep pattern in a BigQuery dataset
# Delete all tables matching a grep pattern in a BigQuery dataset
DATASET=my_dataset
TABLE_PATTERN=my_table_
# Confirm the table names before deleting
for TABLE in `bq ls --max_results=10000 $DATASET | grep TABLE | grep $TABLE_PATTERN | awk '{print $1}'`; do echo $TABLE; done
# Delete the tables; USE WITH CAUTION!
for TABLE in `bq ls --max_results=10000 $DATASET | grep TABLE | grep $TABLE_PATTERN | awk '{print $1}'`; do echo $TABLE; bq rm -f -t $DATASET.$TABLE; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment