Live data from Hacker News

Show HN: Choose – An alternative to cut and sometimes awk

github.com

21–30 of 49 posts

Re: Show HN: Choose – An alternative to cut and sometimes awk

#21
post #3

I can't understand why you are mentioning awk. Cut or choose cannot be compared to awk, awk is a programming language. Also I don't think that it's so much easier to use than cut. On the other hand every *nix system has cut so if you make scripts with it they are portable.

> regular expression field separators using Rust's regex syntax

This actually makes choose a cut-killer for me. It can be frustrating having to figure out which delimiters to use - tabs or spaces? If spaces, you'll have to chain it with tr, or resort to awk.

Re: Show HN: Choose – An alternative to cut and sometimes awk

#22

Earlier quoted context omitted.

> I can't understand why you are mentioning awk. Cut or choose cannot be compared to awk, awk is a programming language. Because 99% of awk IRL use is just as a fancier cut. It's very rare someone even sets a variable using awk. If you do it, you are a statistical rarity. > Also I don't think that it's so much easier to use than cut. On the other hand every *nix system has cut so if you make scripts with it they are…

> 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.

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

#24
post #3

I can't understand why you are mentioning awk. Cut or choose cannot be compared to awk, awk is a programming language. Also I don't think that it's so much easier to use than cut. On the other hand every *nix system has cut so if you make scripts with it they are portable.

> regular expression field separators using Rust's regex syntax This actually makes choose a cut-killer for me. It can be frustrating having to figure out which delimiters to use - tabs or spaces? If spaces, you'll have to chain it with tr, or resort to awk.

And choose makes it even better by using "\s" as a default separator. So you usually don't have to specify a separator at all.

Re: Show HN: Choose – An alternative to cut and sometimes awk

#25
post #8

Hmm, so compared to cut this 1. saves -f because it doesn’t support cut’s -b and -c modes (edit: actually -c is supported, I just didn’t see it); 2. Uses -f instead of -d, making it rather confusing for cut users; 3. Uses : instead of - for range specifications; 4. Offers an exclusive indexing mode; 5. Misses a bunch of other cut features (assuming coreutils cut). Not sure I see much appeal... Edit: Another thing I m…

To get the appeal, give a generalized cut version of:

    echo -e "foo   bar   baz" | choose -1 -2

Re: Show HN: Choose – An alternative to cut and sometimes awk

#27
post #11

Earlier quoted context omitted.

Tools like rg offer additional features and/or save you from tediously specifying many options. This one gives you -f for free, that’s about it. Detailed comparison: https://news.ycombinator.com/edit?id=23445931

- it supports regex separators. That's a great feature to me. - the default separator is "\s", like python's split(). Just for that I will adopt it: not having to care about tabs/spaces/mixes is a much better experience. - it has negative indexes, again like python. Getting the last field, or the last nth field, is something common enought. I don't want to rewrite the thing with a twisted double "rev" with proper ind…

One more great feature of choose which cut doesn't have: not returning garbage output on garbage input.

If you give cut columns which don't exist, it's going to output the entire source as-is.

Re: Show HN: Choose – An alternative to cut and sometimes awk

#28

Earlier quoted context omitted.

> I can't understand why you are mentioning awk. Cut or choose cannot be compared to awk, awk is a programming language. Because 99% of awk IRL use is just as a fancier cut. It's very rare someone even sets a variable using awk. If you do it, you are a statistical rarity. > Also I don't think that it's so much easier to use than cut. On the other hand every *nix system has cut so if you make scripts with it they are…

> 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.

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

#29

Earlier quoted context omitted.

> 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.

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.

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

#30
post #28

Earlier quoted context omitted.

> 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.

For what it's worth, BSD cut has a `-w` flag for separating on general whitespace.

> 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).

Post reply on HN