grep or awk truncate text in pipe

Viewed 49

I'm trying to write a Make command to pause all dags. Here is what I prepared

for dag in $(shell docker exec -it airflow-webserver-1 airflow dags list | awk '/False/ {print}' | tr -s ' ' | cut -d ' ' -f 1); do \
    docker exec -it airflow-webserver-1 airflow dags pause $$dag; \
done

It works perfectly fine for short dag names. However, if a dag name is longer than 22 characters, then the dag name is truncated to only 22 characters hence airflow dags pause will fail because it can't find the dag name.

I have tried grep 'False' as well but it behaves the same.

For example: airflow dags list returns the following dag entry:

dag-exa-mple-lon-gnames        | dag.py        | dag-owner                  | False 

After awk or grep, it will becomes:

dag-exa-mple-lon-gname        | dag.py        | dag-owner                  | False 

Note the last char s is removed from the dag name as it's the 23rd char.

As suggested by @Mark Setchell in comments, I did | cat -vet and found that the truncated charecters are actually moved into separate lines with empty values in other columns and the alignment are pretty off too. I wonder what ^M$ chars represent? You'll need to horizontally scroll a lot to see the complete output

 ^M$
                                                                                                                                                                                                                                                                                          dag-exa-mple-lon-gname | dag.py    | dag-owner             | True  ^M$
                                      s                   |                        |                       |       ^M$

Could anyone advise?

0 Answers
Related