yq: Can't pipe into yq

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.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 24 (6 by maintainers)

Commits related to this issue

Most upvoted comments

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

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…

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

returns bar

In version:

$ yq --version
yq version 4.5.0

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.

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.

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

It was a rude and entitled post, but i deleted soecifically because you said no one sane would use yq, which I take as a personal atttack against me and users of yq.

I understand, and am sorry that you were frustrated, but I do not tolerate posts like that. See the the code of conduct in the repo for more information.

Fixed: repo not report


From: petrmvala @.> Sent: Sunday, January 30, 2022 11:43:18 PM To: mikefarah/yq @.> Cc: Mike Farah @.>; Mention @.> Subject: Re: [mikefarah/yq] Can’t pipe into yq (#113)

@mikefarahhttps://github.com/mikefarah Can you explain why you’ve deleted my post?

— Reply to this email directly, view it on GitHubhttps://github.com/mikefarah/yq/issues/113#issuecomment-1025135563, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAIZHNOAAUEE3WE72I4S2DLUYUW6NANCNFSM4EJX4FEQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you were mentioned.Message ID: @.***>

@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.

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 '.' -

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

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

if you just need something to print nice YML

alias yq="yq eval -P"

image

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

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

cat file.yml | yq

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