LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-25-2009, 06:00 AM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
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?
 
Old 04-25-2009, 06:04 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
Old 04-25-2009, 06:45 AM   #3
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
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.
 
Old 04-25-2009, 07:11 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
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.
 
Old 04-25-2009, 07:32 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
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.
 
Old 04-26-2009, 03:59 AM   #6
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
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

Last edited by visitnag; 04-26-2009 at 04:02 AM.
 
Old 04-26-2009, 04:11 AM   #7
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy text from the command line fos Linux - Newbie 15 04-25-2009 06:41 AM
Command line gnome file copy stefan_nicolau Linux - Software 2 05-30-2008 09:55 AM
Copy A File Off A CD To The Hard Drive In Command Line nickae77 Linux - Newbie 4 05-21-2004 04:38 AM
Copy text from command line Duukkis Linux - General 8 08-25-2003 01:29 PM
command line CDR / copy file rioguia Linux - Newbie 4 10-05-2002 04:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration