Copy and paste the output of a program
It is a common task to copy the output of a program/script and paste it somewhere else. If the output is short (just some lines), we can select the text easily with the mouse. What about longer outputs?
Until now I’ve been using the following method:
./produce-long-output >a(redirect the output to a temporary file)
gedit a(open the temp file with a text editor)
- CTRL+A (select the whole text)
- copy selected text to the clipboard
- paste text to somewhere else
rm a(remove the temp file)
Recently, I discovered some tools (xclip and xsel) that can copy a text to the clipboard. With them, it is unnecessary to use a temporary file.
./produce-long-output | xsel
It’ll copy the text to the “primary” clipboard that you can paste with the middle mouse button. If you prefer pasting with Shift + Insert, then copy texts to the 3rd clipboard (it is simply called “clipboard”).
./produce-long-output | xsel -b
Life has become a little bit less complicated :)