If you spend any time working in a terminal, you’ll find yourself wanting to extract some bit of data from the output of a command. There are lots of ways to accomplish this: you might use cut
, or craft a sed
or awk
expression that pulls out just the part you need.
But sometimes you just want to grab the relevant output and move on to doing something useful with it – without having to stop and think about a regex or count fields. You might reach for the mouse, but for some folks that is a last resort…
I’ve recently come across the terminal utility yank, which is perfect in this situation. Yank provides an interactive selection interface to copy a field from stdin
.
What does that mean? You can run something like:
docker ps | yank
and then use your arrow keys (or hjkl
) to select the thing you want, such as a container ID. Hit Enter
to copy it to the clipboard and go about your work. You can of course pipe your selection to another command:
docker ps | yank | xargs docker kill
And you can specify a delimiter or a pattern if you need to:
env | yank -d =
Check out the project README for more examples. Yank is easy to install on a variety of platforms – give it a try.