I keep hitting the case where I want to do something along the lines of
ls | pick name | insert-dependent-column first-char-of-name {echo $it.name | cut -c 1} to make a new column like the following:
name | first-char-of-name
----------------------------
foo | f
.hidden | .
Adding that feature feels like it would be a huge increase in the power of what could be done with nu
In general, I'm a big fan of the concept of subcommands (I baked subcommands into thor, a popular Ruby command-line framework back in my Ruby days).
I think this makes a lot of sense, and needs some design. We'll need to get through the current onrush of reported bugs before we'll have bandwidth for new design work, but I think this makes a lot of sense.
I have just faced this limitation today, and the workaround felt a bit wasteful, reading the table twice. It was a small csv file, but I wonder how it would deal if it was bigger.
I'm posting to document the workaround in case someone faces this need of deriving column data.
open flows-creation-date.csv | each { echo $it.creation_date | parse "{year}-{month}-{day}T{rest}" } | merge { open flows-creation-date.csv } | histogram year
馃憤
I could see the insert command being updated to support a block, which would then make it equivalent to the insert-dependent-column mentioned in the original description.
@andrasio do you know if there's a better alternative at the moment, than what @bltavares described?
Thanks to @bltavares, I found a solution to a very common use case: converting files from a format to another. Here's the best one-liner I could find:
ls *.jpg | merge { ls *.jpg | get name | str find-replace ".jpg" ".png" | wrap new_name } | convert $it.name $it.new_name