Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save command output to a file without timestamp info

Tags:

yaml

zsh

schema

dbt

If I run this command on my terminal (https://hub.getdbt.com/dbt-labs/codegen/latest/):

dbt run-operation generate_model_yaml --args "{\"model_name\": "bookings"}"          

I get an output that looks like this:

12:53:32  Running with dbt=1.0.1
12:53:34  version: 2

models:
  - name: bookings
    description: ""
    columns:
      - name: booking_id
        description: ""

      - name: masterclient_id
        description: ""

I want to save it to a file. If I do this:

dbt run-operation generate_model_yaml --args "{\"model_name\": "bookings"}"  > test.yml     

this also gets saved to the output:

12:53:32  Running with dbt=1.0.1
12:53:34  

While my desired output is just this:

version: 2

models:
  - name: bookings
    description: ""
    columns:
      - name: booking_id
        description: ""

      - name: masterclient_id
        description: ""

How can I get rid of the extra time stamp info in the beginning and then save the remaining output in a file?


2 Answers

If you're confident that the output is always structured with those exact two timestamps, you can do:

dbt run-operation generate_model_yaml \
  --args "{\"model_name\": \"bookings\"}" \
  | tail -n +2 | sed '1 s/[0-9:]* *//'

tail -n +2 removes the first line. The sed command removes the timestamp and following whitespace from the second (now first) line.

A quick look at the relevant dbt docs yields

  1. The YAML for a base model will be logged to the command line

So it doesn't seem that you can instruct dbt directly to output the YAML data without the logging timestamps.

like image 100
flyx Avatar answered Dec 04 '25 23:12

flyx


Actually you can run with --quiet flag to omit the logging timestamps, dbt does support this; the flag needs to go right after dbt command:

dbt --quiet run-operation generate_model_yaml --args "{\"model_name\": "bookings"}"  > test.yml     
like image 36
Alex Mirkin Avatar answered Dec 04 '25 22:12

Alex Mirkin