Reputation: 2533
Let's say currently my terminal looks like the following:
neekoy@mypc:~/some/folder$ echo "lala nana"
lala nana
neekoy@mypc:~/some/folder$ l
entrypoint.js helpers/ node_modules/ package.json package-lock.json
neekoy@mypc:~/some/folder$
I want to copy the fourth line from the bottom (the one that contains "lala nana").
I can obviously write a script that uses tput to save the cursor position, switch my cursor's position to a specific line, copy it, and then return to the previous cursor position.
Is there an existent solution or an easier way to accomplish this though?
Upvotes: 0
Views: 331
Reputation: 28
I'm not sure I understand your problem. I would solve it this way, though.
I would put the command into a variable to access it again later. (http://www.tldp.org/LDP/abs/html/varassignment.html)
Here is an example:
neekoy@mypc:~/some/folder$ c=$(echo "lala nana")
neekoy@mypc:~/some/folder$ echo $c
lala nana
Or like in your example:
neekoy@mypc:~/some/folder$ echo "lala nana"
lala nana
neekoy@mypc:~/some/folder$ l
entrypoint.js helpers/ node_modules/ package.json package-lock.json
neekoy@mypc:~/some/folder$ c=$(!-2) #related to https://unix.stackexchange.com/a/33552
neekoy@mypc:~/some/folder$ echo $c
lala nana
Or save the output as text in a file.
neekoy@mypc:~/some/folder$ echo "lala nana"
lala nana
neekoy@mypc:~/some/folder$ l
entrypoint.js helpers/ node_modules/ package.json package-lock.json
neekoy@mypc:~/some/folder$ !-2 > test.txt
echo "lala nana" > test.txt
neekoy@mypc:~/some/folder$ cat test.txt
lala nana
Upvotes: 1