I want to use part of the output of a command run from the command line in another xterm, or as part of a different command. For instance:
> grep error err
Easiest way would be using byobu which uses either tmux or screen in the background. It's a wrapper tool that makes using screen or tmux way more efficient, fast and easy. As such it makes it very simple to copy n paste too.
Once you're in byobu and you have the output you want to copy, you can do the following to copy and then paste it:
byobu by default but u can extend the paste enabled applications by installing xclip and doing some setting in byobu --> watch Introduction to terminal multiplexers - Part 2 from around minute 42 to 48) You may send output directly to the concerned xterm using xterm device no. Here is the command.
xyz$ls /home/ankit/documents/etc/x/y/z > /dev/pts/0
(or watever is the device name, You can get it using command 'w' for opened xterm)
Try it & hope this may solve your problem.
I find XSel is useful in similar situations. It's a tool that manipulates the X selection. For example, this will store the output of your command to the clipboard:
grep error error.log | xsel -bi
You can use GNU screen's copy and paste commands.
Quick tutorial:
screen (or screen myprog my args here)Screen is much more powerful than that (I use it to tab several virtual terminals without the need for a special terminal emulator, and also so that I don't loose my sessions when X crashes or something). To get out of screen, simply end your shell session, or type Ctrl+a, Ctrl+\.
The OP said he didn't want to do this, but here is a unix utils way to do it for posterity. If you learn these little unix utilities they can be quite powerful.
ls $( dirname $( grep error error.log | head -1 | cut -d " " -f 5- ) )
note: syntax from memory
You could also use tmux which has similar capabilities to screen. Once you're in tmux and you have the output you want to copy, you can do the following to copy and then paste it:
tmux only) using Ctrl + B, ]These instructiuons assume emacs key bindings are enabled. For the vi bindings see this comparison or just follow this step-by-step guide.