5 ms·
Show HN: Hck – a fast and flexible cut-like tool
- toastal 5y agoHeck
- valbaca 5y ago> hck is a shortening of hack, a rougher form of cut.
- rashil2000 5y agoLove seeing these modern alternatives to coreutils! Ripgrep, fd, hyperfine, bat, exa, bottom, gdu, wc, sd, hexyl... Yet to find a GNU 'tr' alternative though
- kristopolous 5y agoWhat would you like it to do?
- rashil2000 5y agoIt's not like anyone absolutely needs it, I was just fascinated by the recent surge in faster and more cross-platform utilities.
- kristopolous 5y agoGet it to play nicer with iconv and we've got an improvement
- sieste 5y ago> Ripgrep, fd, hyperfine, bat, exa, bottom, gdu, wc, sd, hexyl... Thanks for that list! Is there any place where more of these "modern alternatives to coreutils" are collected?
- basetensucks 5y agohttps://github.com/ibraheemdev/modern-unix https://github.com/ibraheemdev/modern-unix is a pretty decent list.
- tyingq 5y agoHere's tr in Perl: https://metacpan.org/dist/PerlPowerTools/source/bin/tr https://metacpan.org/dist/PerlPowerTools/source/bin/tr
- ComputerGuru 5y agoHere's `tac` in rust, with simd optimizations (in the simd branch, I haven't gotten around to releasing it although the only thing missing is dynamically detecting simd support instead of doing it at compile time): https://github.com/neosmart/tac https://github.com/neosmart/tac and `rewrite`, which I've been told is akin to gnu sponge, "rewritten" in rust: https://github.com/neosmart/rewrite https://github.com/neosmart/rewrite
- marto1 5y agoRipgrep is really the one that stood out for me. It feels substantially faster to use and does seem to do sane things more often than grep. Would recommend anyone to try it.
- lillesvin 5y agoI wrote something similar (but necet really finished it), called 'gut', in Go a few years back. Funny thing is, that I literally never use it. I thought splitting on regexes and that stuff would be super useful, but it turns out that I just use Perl one-liners instead. And Perl is available on something like 99.99% of all *nix machines, which my own 'cut'-substitute isn't. Still a good exercise for me to write it, and I assume for OP too.
- mongol 5y agoA book "Minimal Perl" used to be referred to often in these discussions but I never hear about it any more. It was teaching these kind of tricks for command line magic.
- c54 5y agoI’ve never used perl, but i love concise bash 1-liner wizard incantations. What are some examples of things it’s handy for?
- atsaloli 5y agoSee https://catonmat.net/perl-one-liners-explained-part-one https://catonmat.net/perl-one-liners-explained-part-one And https://nostarch.com/perloneliners https://nostarch.com/perloneliners
- asicsp 5y agoI wrote a couple articles showing examples where Perl is more suitable compared to sed/awk: * https://www.perl.com/article/perl-one-liners-part-1/ https://www.perl.com/article/perl-one-liners-part-1/ * https://www.perl.com/article/perl-one-liners-part-2/ https://www.perl.com/article/perl-one-liners-part-2/
- totalperspectiv 5y agoIt was indeed an great exercise! Part of the motivation for me was also performance oriented. I should add some Perl one liners to the benchmarks to see where they land as well. My experience is that they are usually a bit slower than awk.
- bilalhusain 5y agoIt is interesting to note how it compares to "choose" (also in Rust) in the benchmarks. single character hck 1.494 ± 0.026s hck (no-mmap) 1.735 ± 0.004s choose 4.597 ± 0.016s multi character hck 2.127 ± 0.004s hck (no-mmap) 2.467 ± 0.012s choose 3.266 ± 0.011s The single pass optimization trick[1] seems to be helping a lot in single character case. Of course, doing away with a pass is suppossed to give 2x, and I am wondering whether the regex constraint lead to this "side-effect". [1] fast mode - https://github.com/sstadick/hck/blob/master/src/lib/core.rs#L194 https://github.com/sstadick/hck/blob/master/src/lib/core.rs#... https://github.com/sstadick/hck/blob/master/src/lib/core.rs#L324-L331 https://github.com/sstadick/hck/blob/master/src/lib/core.rs#...
- kitd 5y agoNice work! I don't know whether anyone here has used Rexx. The 'parse' instruction in Rexx was incredibly powerful, breaking up text by field/position/delimiter and assigning to variables all in one line. I've often wondered if there was a command-line equivalent. Awk is great but you have to 'program' the parsing spec, rather than declare it.
- twic 5y ago> Awk is great but you have to 'program' the parsing spec, rather than declare it. You could probably turn a declarative spec into an awk program with an awk program.
- tyingq 5y agoNot declarative, but Perl can do something like that. Delimeters/Regex: $ perl -ne '($name,$pass,$uid,$gid,$therest)=split(/:/);print "$name $gid\n"' /etc/passwd root 0 daemon 1 bin 2 ... Fixed width: $ printf "1234XY\n5678AB" | perl -ne '($f1,$f2)=unpack("a4 a2");print "$f2 $f1\n"' XY 1234 AB 5678 I believe Rexx's parse is fancier still, but this is reasonably close.
- queuebert 5y agoYay, no more piping multiple cuts when you have multiple delimiters.
- visarga 5y ago<offtopic> I have implemented a `_split` command to split a line by a separator and `_stat` command that does basically `sort | uniq -c | sort -nr` counting elements and sorting by frequency. Really useful operations for me. When my one liners become 2-3 lines long I need to switch to a regular script, but I also log all my shell commands years back and have something a bit better than `history | grep word` to search it.</>
- nerdponx 5y ago> I also log all my shell commands years back and have something a bit better than `history | grep word` to search it. I'd be very interested to hear more about this.
- technological 5y agoNice one op. It’s mostly due to my lack of knowledge of rust but the code is not easy to read unlike golang. Does anyone feel the same ? (between nothing to do with how op wrote but rather the language itself)
- tyingq 5y agoI don't think even Rust fans would argue that. Rust has roughly 2x the amount of reserved words, more operators, and so on. There's a larger basic set of things to learn before you could skim some code and read it.
- asicsp 5y agoI saw about `hck` recently on twitter, was impressed to see support for compressed files. From the current todo list, I hope complement is implemented for sure. I see Negative index is currently "unlikely". I'm writing a similar tool [0], but with bash+awk. I solved the negative index support with a `-n` option, which changes the range syntax to `:` instead of `-` character. My biggest trouble came with literal field separator [1], because FS can only be specified as a string in awk and backslash is a metacharacter for both string and regexp. [0] https://github.com/learnbyexample/regexp-cut https://github.com/learnbyexample/regexp-cut [1] https://learnbyexample.github.io/escaping-madness-awk-literal-field-separator/ https://learnbyexample.github.io/escaping-madness-awk-litera...
- rendall 5y agoThe README and description should not assume the reader knows what `cut` is or what it's used for. Maybe reference it and then ELI5