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

Add Array/String Slice #44

Closed
kenjones-cisco opened this issue Sep 27, 2017 · 5 comments
Closed

Add Array/String Slice #44

kenjones-cisco opened this issue Sep 27, 2017 · 5 comments

Comments

@kenjones-cisco
Copy link
Contributor

kenjones-cisco commented Sep 27, 2017

Add support for Array/String Slice

The .[10:15] syntax can be used to return a subarray of an array or substring of a string. The array returned by .[10:15] will be of length 5, containing the elements from index 10 (inclusive) to index 15 (exclusive). Either index may be negative (in which case it counts backwards from the end of the array), or omitted (in which case it refers to the start or end of the array).

Expected

a: Easy! as one two three
b:
  c: 2
  d: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  e:
    - name: fred
      value: 3
    - name: sam
      value: 4
$ yaml r sample.yaml  b.d[2:5]
- 5
- 6
- 7
- 8
@kenjones-cisco kenjones-cisco added this to the 1.14.0 milestone Sep 27, 2017
@mikefarah mikefarah removed this from the 1.14.0 milestone Jul 23, 2019
@ryenus
Copy link
Contributor

ryenus commented Apr 14, 2022

@mikefarah, possible to revisit this? Any chance to resurrect?

This is really helpful in case the input is not strictly json for jq to accept, meanwhile ok for yq.
so, instead of first passing the input array data first to yq, and normalized for jq to extract the wanted slice of the array. It would be great to be able to process the data just once in yq and extract the array slice in place, especially when the amount of input data is large.

@RichardBronosky
Copy link

@mikefarah was this closed unintentionally? No comments or commits were ever made.

@mikefarah mikefarah reopened this Jun 28, 2022
@mikefarah
Copy link
Owner

Oops - sorry yeah closed unintentionally.

@mikefarah
Copy link
Owner

Fixed (finally) in 4.29.1

@psmolkin
Copy link

In the end, does it work for strings? Didn't find anything in the docs.

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

No branches or pull requests

5 participants