How to copy command line commands into a text file...
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to copy command line commands into a text file...
Hi,
Generally many times I test a code (either bash or awk) on command line. Sometimes it is very long command. My problem is how to copy this command line command into a vi editor? Presently i am doing like this..
$echo "my command" > somefile. Here what is happening the command is copied but it is missing double quotes in the command. For example.
My command is:
$awk '{sum+=$1}END{printf "%12.2f\n",sum}' input
if i write the above command using echo into my editor...the double quotes in the printf function are missing. So how can i copy my commandline command into vi as it is?
Output redirection:
0 = stdin input device such as keyboard
1 = stdout output device usually the console
2 = stderr error message usually displayed at the console
ls nofile > file.txt 2>&1 This sends stdout and stderr to a file.
ls | tee file.txt This sends stdout to the screen and to a file.
(ls 2>&1) | tee file.txt This sends stdout and stderr to the screen and to a file.
If you use the 'gpm' as suggested then you can highlight the command line then with your open 'vi' in insert you can click the right mouse button to place the buffer at the cursor point.
You do know that the command line has a buffer that you can scroll through and edit via the arrow keys along with the keyboard edit keys. You can utilize these with 'gpm' to enhance your session.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.