Skip to content

What's the function to extract the last value of an array? #1333

Answered by johnkerl
aborruso asked this question in Q&A
Discussion options

You must be logged in to vote

Is there some -1 way to do it?

@aborruso yes, exactly:

$ echo 'input=ciao;bau;miao' | mlr --ojson put '$array=splita($input,";")'
[
{
  "input": "ciao;bau;miao",
  "array": ["ciao", "bau", "miao"]
}
]

$ echo 'input=ciao;bau;miao' | mlr --ojson put '$array=splita($input,";")[-1]'
[
{
  "input": "ciao;bau;miao",
  "array": "miao"
}
]

Please also see
https://miller.readthedocs.io/en/latest/reference-main-arrays/#negative-index-aliasing

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aborruso
Comment options

Answer selected by aborruso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants