I need a tool or utility that can take a text file and copy each line onto the clipboard in a way so I can paste back the text line by line by continuously pressing Ctlr-V.
For example, if the text holds these lines
line 1
line 2
line 3
Then I will get:
Ctlr-v: line 1
Ctlr-v: line 2
Ctlr-v: line 3
I need it for pasting lines into the terminal when debugging telnet sessions. It is very tedious to copy and paste the lines one by one.
Does such a tool exists, or can it be created using xclip or similar?
It is for Debian based distros if that makes any difference.
Note:
See don_chrissti's comment for a variation to the accepted solution that worked for me.
Addition:
This is the script I ended up with. Note the use of double backslash to retain the newlines from the text file.
while IFS= read -r line; do
printf %s\\n "$line" |
xclip -l 1 -quiet -selection primary
done < telnet
It works very well for testing smtp connections over telnet which is my use of it.
Best Answer
With
xclip
:Replace
%s
with%s\n
if you need the newline included.With
-l 1
xclip holds theCLIPBOARD
selection for one request (by other applications doing Ctrl-V for instance), and then exits. You need-quiet
forxclip
to do that in foreground.That won't work if you have an application like
xclipboard
running. Those applications try to always be the owner of theCLIPBOARD
selection, so will steal it continuously fromxclip
.If you have such an application running, you can either suspend or kill it, or you could use the
PRIMARY
selection instead (-selection primary
, or omit-selection
asprimary
is the default) and paste using the middle mouse button. Many terminal emulators can paste thePRIMARY
selection upon Shift-Insert, some other upon Ctrl-Shift-Insert.If you want to know who is stealing the CLIPBOARD selection from
xclip
, this may work:provided that application offers the CLIENT_WINDOW target (run
xclip -selection clipboard -o -t TARGETS
to see if it does).See also
expect
(anddejagnu
for a testing framework based onexpect
) and GNUscreen
to automate inserting text into terminal applications.