LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to copy command line commands into a text file... (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-copy-command-line-commands-into-a-text-file-721565/)

visitnag 04-25-2009 06:00 AM

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?

Nylex 04-25-2009 06:04 AM

Select the text with the mouse, run vi and paste the text with the middle mouse button. This assumes you have gpm running, but usually you do.

arizonagroovejet 04-25-2009 06:45 AM

Add this to your .bashrc
Code:

alias elc='history -a ; tail -2 $HISTFILE | head -1'
To write the last command in a file use

Code:

$ elc > filename
I'd be interested to see if anyone has a more elegant solution.

homey 04-25-2009 07:11 AM

Maybe output redirection would work for you.
Code:

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.


onebuck 04-25-2009 07:32 AM

Hi,

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.

visitnag 04-26-2009 03:59 AM

Hi arizona....
your code is not working...its giving a # followed by some digits as ouput... what must be the wrong ? I am using ubuntu8.1

example:
#1240736419

arizonagroovejet 04-26-2009 04:11 AM

Dunno. Works for me. Did you remember to source your .bashrc or log out and in again after making the change to your .bashrc?


All times are GMT -5. The time now is 09:57 PM.