News for hackers. Stuff that matters.
Re:Show HN: Choose – An alternative to cut and sometimes awk by masklinn on Sunday June 07, 2020 @06:02AM (#23446150)
> Because 99% of awk IRL use is just a as fancier cut.

You say "fancier", I say "working": since cut can't work on general whitespace without a pre-processing phase (e.g. tr), it simply doesn't work for the vast majority of the things I try to shove into it, and I pretty much always end up using awk instead.

Choose means my awk use will fall down by 99% or so.

Re:Show HN: Choose – An alternative to cut and sometimes awk by BiteCode_dev on Sunday June 07, 2020 @06:12AM (#23446194)
Agreed.

In fact, anybody promoting cut, please give me the cut version of:

    echo -e "foo   bar   baz" | choose -1 -2
It should work on an arbitrary number of spaces, and fields.

The oneliner is going to be... interesting.

Now you can do it with awk using:

   echo -e "foo bar baz" | awk '{ print $NF " " $(NF-1)}'
But it's neither easy to type, nor to remember.

Choose is what cut should have been.

Re:Show HN: Choose – An alternative to cut and sometimes awk by errnoh on Sunday June 07, 2020 @07:33AM (#23446633)
By using only basic functionality that's easy enough to remember I guess I'd go with something like

`echo -e "foo bar baz" | tr -s ' ' | rev | cut -d ' ' -f 1-2 | rev | awk '{print $2 " " $1}`

Everything except the awk part is something that I use all the time and is easy to type & remember.

To be honest I'd use `choose` if it was available everywhere, but for string manipulation I can't justify using nonstandard tools since they aren't always available.

Every now and then there are some new ones I actually start to use. For example `ripgrep` mostly replaced `grep -R` for me some time ago, a lot of it has to do with the fact that if `rg` is not found I can fallback to normal grep and get the same result, just a bit slower.

I guess my point is that while I do appreciate innovation & making better tooling, the hard part always is getting the tool where it's most needed.

Re:Show HN: Choose – An alternative to cut and sometimes awk by Brian_K_White on Monday June 08, 2020 @06:10PM (#23461375)
cut? I don't even leave the shell.

echo ... |while read a b x ;do ... ;done

Re:Show HN: Choose – An alternative to cut and sometimes awk by darrenf on Sunday June 07, 2020 @07:02AM (#23446475)
For what it's worth, BSD cut has a `-w` flag for separating on general whitespace.
Re:Show HN: Choose – An alternative to cut and sometimes awk by masklinn on Sunday June 07, 2020 @08:01AM (#23446763)
> BSD cut

Only FreeBSD, and it's somewhat recent (it was apparently added in 2012, in 9.2, so it's not in osx either).