'save command output to a file without timestamp info

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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 flyx