Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pipe into yq #113

Closed
andrewsav-bt opened this issue Dec 28, 2017 · 24 comments
Closed

Can't pipe into yq #113

andrewsav-bt opened this issue Dec 28, 2017 · 24 comments

Comments

@andrewsav-bt
Copy link

Piping into yq with my.yml | yq does not seem to work, which limits usability for scripting on linux severely. This needs to be supported.

@mikefarah
Copy link
Owner

@spuder
Copy link

spuder commented Jan 29, 2019

You have to do this yq r -. Really wish this was simpler.

echo -e '---
foo: bar' | yq r -

Also it doesn't work reliably with tools like helm. It only returns the first yaml document, even if there are more.

helm template foo

@mikefarah
Copy link
Owner

That's what it does by default, you can specify a specific document or all documents:

http://mikefarah.github.io/yq/read/#multiple-documents-specify-a-single-document

@spuder
Copy link

spuder commented Jan 29, 2019

So looks like yq r - -d '*' is the solution to pipe to yq.

echo -e '---
foo:bar
---
buzz:42
' | yq r - -d '*'

@ovidiubuligan
Copy link

I hope the defaults will change to something smarter . To just do mycommand | yq just like jq.

@RSwarnkar
Copy link

RSwarnkar commented Dec 4, 2020

Hi guys, I see It does not do the syntax highlighting when piped. Please help!

ppp

@lindhe
Copy link

lindhe commented Jan 19, 2021

Was this functionality removed? I can't get it to work...

EDIT: Yep! Seems like this changed with v4 of yq. Now we have to run yq eval for things to work from stdin. I find it incredibly annoying that eval is not the default behaviour when just running stuff | yq since that's how jq works...

@czerasz
Copy link

czerasz commented Feb 8, 2021

echo -e '---
foo: bar
buzz: 42
' | yq e '.foo' -

returns bar

In version:

$ yq --version
yq version 4.5.0

@kubosuke
Copy link

kubosuke commented Mar 9, 2021

@RSwarnkar
I got hilighted yaml by:

cat tmp.yaml | yq -C r -
yq version 3.4.1

@tliron
Copy link

tliron commented Apr 16, 2021

The use of - to specify stdin processing does not seem to be mentioned in the command help. I had to find this issue to learn about it.

@mikefarah
Copy link
Owner

Good idea - I'll put it into the command help (for v4)

@fabiopaiva
Copy link

fabiopaiva commented Jun 16, 2021

if you just need something to print nice YML

alias yq="yq eval -P"

image

@mabushey
Copy link

mabushey commented Sep 16, 2021

Has anyone figured out how to do this with V4? yq e by itself pretty prints, but then assumes anything (ie .name) else is a filename. It's IMPOSSIBLE to find correct docs because there are so many incompatable versions and different releases.

@mikefarah
Copy link
Owner

Sorry to hear that, the documentation is referenced from this page, you can select the correct version on the RHS, the default is version 4.

yq's built in help docs also document how to do read from stdin:

yq e --help

For what it's worth, I've just added reading from STDIN as an example in the quick guide of the Github readme.

@sezu
Copy link

sezu commented Sep 16, 2021

Has anyone figured out how to do this with V4? yq e by itself pretty prints, but then assumes anything (ie .name) else is a filename. It's IMPOSSIBLE to find correct docs because there are so many incompatable versions and different releases.

Try yq e '.' -

@mabushey
Copy link

mabushey commented Nov 2, 2021

Thanks @sezu . I keep coming back here via google trying to figure out how to do this repeatedly as this is so anti-intuitive.

Repository owner deleted a comment from petrmvala Jan 27, 2022
@mikefarah
Copy link
Owner

Did some black magic, and with the latest release (4.18.1) you no longer have to specify e or -:

cat file.yml | yq

@petrmvala
Copy link

@mikefarah Can you explain why you've deleted my post?

@mikefarah
Copy link
Owner

mikefarah commented Jan 30, 2022 via email

@tliron
Copy link

tliron commented Jan 30, 2022

@mikefarah Thank you for volunteering your time to work on this project. This latest fix is very welcome and makes it more pleasant to use for us pseudo-sane people. :)

For those unhappy few, I'm sure you are welcome to contribute patches, fork, or start your own alternative project.

@petrmvala
Copy link

There was nothing rude about the post I made. I barely mentioned that 99.9% of macos/linux tools work the same way and use the same verb structure.
This way, all the tools can do things as piping commands and using CLI a coherent experience.

You have made a tool to manipulate yaml. That is a good idea, and thank you for that. However, you have named the tool yq, which obviously reflects on a very popular tool jq. It is quite natural to expect the CLI tool to behave like most CLI tools do. Furthermore, it is quite natural to expect very similar behavior to jq.

Your tool, however, doesn't behave like jq and doesn't behave like all other CLI tools either. If this behavior were so sane, why is there this thread filled with several attempts to understand basic functionality?

The fact that this is probably a bad functionality decision is not a personal attack.

@jeffsani
Copy link

I was able to Anyone know which switch to use to remove the "-" from the output? FYI - I am on 4.16.1 and I still had to use the "e" eval directive to get yq working with piped curl output.

@btpka3
Copy link

btpka3 commented Dec 5, 2023

Found when using yq v4.40.4 with pipe / stdin, flag -p is needed, otherwise there's no output
( input format is guessed by file name suffix but there no filename for stdin?) .

# check yq version
yq -V

# prepare test data   
xml='
<project>
  <profiles>
    <profile><id>aaa</id></profile>
    <profile><id>bbb</id></profile>
    <profile><id>ccc</id></profile>
  </profiles>
</project>
'
echo $xml > /tmp/a.xml

# test 1 :  worked
echo $xml | yq eval -p xml -o json '.project.profiles.profile[].id'
# test 2 :  worked
yq eval -p xml -o json '.project.profiles.profile[].id' < /tmp/a.xml

@dbsanfte
Copy link

I feel like if no file is specified, yq should be like jq and default to reading from stdin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests