Show HN: Tuc – When cut doesn’t cut it (github.com)
Announcing `tuc`, a utility similar to coreutils `cut`, but more powerful.
It allows to split text or bytes into parts and reassemble them in any order.
I always found `cut` very practical for some tasks where `sed` or `awk` were overkill or awkward to use, but I also felt the need for more features.
Some key differences from `cut`: - parts can be referenced by negative indexes - delimiters can be any number of characters long, or match a regex - can split text into lines, and reassemble them
120 comments
[ 3.4 ms ] story [ 171 ms ] threadIn the context of "cut", it would mean being able to do something like:
cut -d" " -f1--2
the "-f1--2" (read: fields from 1 to minus 2; it's a range) means to select from the first field to the second-to-last field. (that double "--" is pretty awkward, to be sure!)
Some programming languages (ruby is the one that I know) have this feature for accessing array elements.
The main advantage of tuc seems to be "templated" outputs.
Good question, I struggle to word it properly, any help is appreciated.
Assume a file (we will call it "input"), such as
You can use a delimiter and cut inside each linee.g.
or you can cut it "by lines", practically considering the whole file as your single "line" and using newline as delimiter If you want to remove a line, or keep something inbetween it can be more practical/intuitive than head/tail or sedMaybe a good way to explain it would be to show how to achieve the same thing with those well known commands (comparison which should certainly be in favor of tuc ^^)
EDIT: sorry you just said more or less the same thing, I need to read better :)
It's not. `tuc` is a superset of cut and in that particular example there's no difference. If you wanted instead to cut on multibyte delimiters, or on a random amount of spaces, `tuc` would work, while `cut` would fall short
Thanks for trying it out!
Or you can just stick with the old tools if you prefer not learning a new thing - that's a perfectly valid option.
https://github.com/sharkdp/fd/releases/download/v8.4.0/fd-mu...
I mean, I get it — I used to locally install vim on machines that only had vi, to make my muscle memory be functional when editing files. But it’s not the same as a core tool just being available by default so you don’t have to ever concern yourself with any alternatives.
For example
I wonder if something like this exists for rustIf you shouldn't trust it but you do anyway and someone uses that against you - they exploited your trust.
Your scripts could have a prolog that installs rustup and calls cargo.
There is also https://github.com/ryankurte/cargo-binstall
Even after 20 years of bashing, my bash skills still suck. So many corner cases!
But if you include this, and call install_utils at the head of your scripts. It should install the tools on demand.
I don't recommend using this, it is just illustrative."Modern" dev environments are often tied to their own package manager. JS has Npm, Rust has Cargo, etc... These have their own dependency managers, version systems, etc... and they don't always get along with the way Linux package managers work.
IIRC, you don't even need Cargo to do Rust, so it should be possible to compile Rust projects like you compile C projects and essentially mirroring crates.io but with .deb packages but it looks like a lot of work.
https://packages.debian.org/stable/rust/
https://crates.io/crates/cargo-deb exists but I don’t know if Debian uses it or something else.
If you get anywhere in the neighborhood of a proper superset of the old application, we do occasionally retire the old ones.
>Here, I don't have to chase the next bride.
Who hurt you? :)
So maybe don't project about "hip" or "young" because it does your otherwise decent argument a disservice.
Never understood why that was never added to cut in the first place.
Slightly off topic question about this: in Linux, are rust programs always installed like this, or should these also be made available in the regular package manager of your distro?
(But also it's your system. What's the point of Linux if you can't do it your way)
Getting a package in the official repositories is quite a high bar to clear.
Plus it's... not great experience for early development, as many distros will lock in the program entirely, leaving you with a very long tail of extremely outdated installs.
So generally the expectation is that once a program is popular or desirable enough, and is somewhat stable, it gets integrated into the base repos.
There's pip for python, npm for JS, cargo for rust
For C/C++ all I know are multiple different possible build and make systems, but none works like a package manager, as far as I know
Note that I don't always love when something installed with pip or npm puts files all over your OS or homedir without being managed by the package manager, though
And maybe I need to install one or two dependencies, similarly they should be familiar, or small and comprehensible, and only downloaded and installed with my explicit actions.
(And yeah autoconf generated configure scripts are crazy huge and baroque, and could easily be 1/10 the size for the needed functionality, but compared to "npm install" I'll take it.)
Downloading the source by hand, trying to wrangle what dependencies it has not vendored (which may or may not be available through your system package managers, in versions which may or may not be recent enough), and trying to find out how to build it.
Though do note that this issue can also hit when installing python, js, or rust package, if they ultimately have native dependencies. Their respective build systems will generally try to make it work out of the box, but if your configuration was not specifically tested / supported it can break with fun C-level compilation errors.
It's awesome. And complicated.
[0] https://pypa.github.io/pipx/
In general, end users should use some other method that doesn't require having a Rust toolchain pre-installed, but doing that can take work, and so not every program pursues it.
While not my primary role at my job, I often find myself dealing with lots of disparate data sets, usually needing to do some sort of manipulation, cleaning, searching, etc. Every now and then encounter something like this and it seems to me that there are potentially a nice set of command line tools/utilities that I should be adding to my belt. Anywhere I should particularly start taking a look? Like, if my goal is to because much better at wrangling CSV/text-delimited files, searching across folders of docs for numbers, etc., where is my first entry point into trying to become much more proficient at it?
There are even more. :)
also mdfind if you're on macos
I'm hesitant to go fully into "new" stuff so I can maintain skills on random *nix boxes I need to ssh into.
For searching recursively through folders, I recommend ripgrep (rg), though it won't do number conversions and the like.
Self-promotion (but I think it's useful here) is my GoAWK project, which is a POSIX-compatible version of AWK, with the recent addition of proper CSV support: https://benhoyt.com/writings/goawk-csv/
For a 45-year old language, it's actually surprisingly good. There are a few annoyances and clumsy things (getting substrings is a function call without nice str[start:end] syntax, regex matches are harder than they need to be, string concatenation syntax is weird, arrays aren't nestable (except in Gawk), and so on).
I've actually thought it'd be great to "fix" these things and make a nicer AWK language, but the problem is then no one would use it. :-)
They're from BSD originally. Included in macos, and in Linux distros as bsd-utils.
Quite the opposite, early on I started with `clap`, then moved briefly to `argh` before settling with `pico-args`. Compilation time and size where the main driving factors, alonside support for non-spaced values (e.g. -d' ').
Maybe if tuc had subcommands it would have been a different story, but I didn't find enough value in more blasoned arg libraries.
(I see that it support splitting on regex but I was hoping for it to be the default or a single character switch)
Edit: or maybe not, I think I'd still have to use --regex for real whitespace sequences that can be a mix of spaces and tabs.
In either case, very cool. Thanks for sharing. I’ll be using this for sure!
See also:
* hck (https://github.com/sstadick/hck) - close to drop in replacement for cut that can use a regex delimiter instead of a fixed string
* rcut (https://github.com/learnbyexample/regexp-cut) - my own bash+awk script, supports regexp delimiters, field reordering, negative indexing, etc