kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.58k stars 83 forks source link

Output array to space seperated string ? #92

Closed stuaxo closed 4 years ago

stuaxo commented 4 years ago

I'd like to compare the some content in a yaml file with a list I already have in an environment variable, seperated by spaces.

Is there a way I can get the list of item values output on a single line by yq ?

kislyuk commented 4 years ago

What have you tried?

stuaxo commented 4 years ago

I got as far as $ yq r .travis.yml addons.apt.packages | cut -f2 -d\ | tr '\n' ' '

But wondering if there is a more native solution.

kislyuk commented 4 years ago

You are in the wrong repo; you are looking for another utility by the same name.

kislyuk commented 4 years ago

With yq, apt-get install $(yq -r .addons.apt.packages[] ~/projects/query-service/.travis.yml) works. If you must get a space separated string, I would do for i in $(yq ...); do echo -n "$i ".

stuaxo commented 4 years ago

The square bracket syntax doesn't work for me, maybe my travis is in a different format:

https://github.com/shoebot/shoebot/blob/master/.travis.yml

I can't work out how to get the square bracket syntax to work. Using $() works, though I would still get lots of -. so will need to use cut:

echo $(yq r .travis.yml addons.apt.packages) build-essential - gir1.2-gtk-3.0 - gir1.2-rsvg-2.0 - gobject-introspection - libgirepository1.0-dev - libglib2.0-dev - libjpeg-dev - libpango1.0-dev - python-gi-cairo - python-gobject - python3-dev

stuaxo commented 4 years ago

I'll do this in a python script in the end, cheers for the help.

stuaxo commented 4 years ago

Apologies, just saw your comment about this being the wrong repo.

Arg, sorry about that !