3

I have a query $(bq query --format=csv "select value from $BQConfig where parameter = 'Columnwidth'") .

The output of the query in csv format is :

value 3 4 6 8

here i want to get only the result 3 4 6 8 not the value which is just a header.

I have gone through google document and found that --noprint_header works only for bq extract. i didnt find anything for bq query.

Adt
  • 313
  • 6
  • 20
  • Possible duplicate of [Assigning the output of a BQ query to variable](https://stackoverflow.com/questions/45351830/assigning-the-output-of-a-bq-query-to-variable) – Graham Polley Jul 31 '17 at 22:02
  • https://stackoverflow.com/questions/36837581/extract-files-from-gbq-to-gcs-without-csv-header-using-bq-command-line/36842915#36842915 solves this – Daniel Molnar Feb 26 '18 at 12:38

2 Answers2

6

If you are on a bash shell, you could use sed or awk to skip the first lines:

 bq query --format=csv "SELECT 1 x" | sed "2 d"

Or:

 bq query --format=csv "SELECT 1 x" | awk 'NR>2'
Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325
-3

You can use the --skip_leading_rows argument (source : Create a table from a file)

  • I changed my query as `$(bq query --skip_leading_rows=1 --format=csv "select value from $BQConfig where parameter = 'Columnwidth'")`. But now i am getting error as `FATAL Flags parsing error: Unknown command line flag 'skip_leading_rows'` . Please let me know if you need any other information – Adt Jul 31 '17 at 13:22
  • Why don't you just load the csv's into BQ and the query it? When loading you can `bq load --source_format=CSV --skip_leading_rows=1` or even use the auto detect schema flag. Then querying will be trivial – Manos Parzakonis Jul 31 '17 at 14:35
  • 5
    `skip_leading_rows` is for `load`, not `query`. – Graham Polley Jul 31 '17 at 22:01