Created
February 26, 2019 23:24
-
-
Save justinnaldzin/721dc6924f2d428a8f886b2a099cd758 to your computer and use it in GitHub Desktop.
Delete all tables matching a grep pattern in a BigQuery dataset
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
# 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