Skip to content
\n

So I can do arithmetics on the amount of apples and bananas. Which is the missing command?

\n

Another way to put the question: How do I run a command for every column of a row?

","upvoteCount":3,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

When you parse the string you end up getting two columns of strings. One way would be to convert the columns to integer. I always use the command describe to understand what I'm working with.

\n

This will show you that they are parsed as strings
\necho \"12apples 25bananas\" | parse \"{apples}apples {bananas}bananas\" | describe

\n

Then you can convert the columns into integer. You could run describe on this to see the outcome
\necho \"12apples 25bananas\" | parse \"{apples}apples {bananas}bananas\" | into int apples bananas

\n

Then to run on each row you use the command each. $it indicates item/iterator meaning row here.
\necho \"12apples 25bananas\" | parse \"{apples}apples {bananas}bananas\" | into int apples bananas | each { echo $\"you have (($it.apples) + ($it.bananas)) fruit\"}

","upvoteCount":1,"url":"https://github.com/nushell/nushell/discussions/4148#discussioncomment-1709519"}}}
Discussion options

You must be logged in to vote

When you parse the string you end up getting two columns of strings. One way would be to convert the columns to integer. I always use the command describe to understand what I'm working with.

This will show you that they are parsed as strings
echo "12apples 25bananas" | parse "{apples}apples {bananas}bananas" | describe

Then you can convert the columns into integer. You could run describe on this to see the outcome
echo "12apples 25bananas" | parse "{apples}apples {bananas}bananas" | into int apples bananas

Then to run on each row you use the command each. $it indicates item/iterator meaning row here.
echo "12apples 25bananas" | parse "{apples}apples {bananas}bananas" | into int apples ba…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@raffomania
Comment options

@Xevion
Comment options

Answer selected by raffomania
Comment options

You must be logged in to vote
2 replies
@weirdan
Comment options

@Xevion
Comment options

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