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

Incorrect length with wc -l #362

Closed
lee5i3 opened this issue Feb 17, 2020 · 3 comments
Closed

Incorrect length with wc -l #362

lee5i3 opened this issue Feb 17, 2020 · 3 comments
Labels
Milestone

Comments

@lee5i3
Copy link

lee5i3 commented Feb 17, 2020

We are getting an incorrect length of records when piping wc -l with v3

YAML

dependencies:
  - item1
  - item2
  - item3
  - item4

docker run --rm -v ${PWD}:/workdir mikefarah/yq:latest yq r ./file.yaml dependencies[*] | wc -l
returns a length of 3

docker run --rm -v ${PWD}:/workdir mikefarah/yq:2 yq r ./file.yaml dependencies[*] | wc -l
returns a length of 4 (which is correct)

@lee5i3
Copy link
Author

lee5i3 commented Feb 17, 2020

Workaround we used to temporarily solve this was adding an empty entry

dependencies:
  - item1
  - item2
  - item3
  - item4
  - 

Anyway do handle this with yq alone without using wc -l to give us the array count?
We can also use
docker run --rm -v ${PWD}:/workdir mikefarah/yq:latest yq r ./test.yaml -j | jq '.dependencies' | jq length but would rather only use yq if possible

I'm also noticing when I use v2 its returning

- item1
- item2
- item3
- item4

where v3 is returning

item1
item2
item3
item4username@mylaptop $

@mikefarah
Copy link
Owner

Ah I see the lack of trailing newline is causing that.

If you leave out the splat then it works

yq r examples/data1.yaml dependencies | wc -l

I'm thinking I should make it always append a new line?

@mikefarah mikefarah added the bug label Feb 17, 2020
@mikefarah mikefarah added this to the 3.1.2 milestone Feb 20, 2020
@mikefarah
Copy link
Owner

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

No branches or pull requests

2 participants