[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pasting text into bash without use of mouse



on Mon, Apr 09, 2001 at 02:06:50AM +0800, csj (csj@mindgate.net) wrote:
> On Sunday 08 April 2001 08:48, Karsten M. Self wrote:
> > on Sun, Apr 08, 2001 at 07:38:11AM +0800, csj (csj@mindgate.net) 
> wrote:

> > > Taking a breath of humid air:
> > >
> > > Let's say I have a file "commands.list" which contains a series
> > > of commands. One is the line:
> > >
> > > (1) find * -name *.htm | grep -h "http://www.foo.org"; > foo.txt
> > >
> > > I want now to do:
> > >
> > > (2) find * -name *.htm | grep -h "http://www.foobare.org"; >
> > > foo.txt
> > >
> > > I would extract the first command (1) from "commands.list" by
> > > typing
> > >
> > > grep "www.foo.org"
> > >
> > > which would of course print to the default stdout, e.g. the
> > > terminal. End of story. That's all I get. But if there's some way
> > > to "pipe" or "paste" (note the quotes of doubt)  the output of
> > > grep and friends to the command line itself, I can simply use
> > > bash's line-editing functions to morph command (1) to command
> > > (2). No mousing around (admittedly not much of a gray-xercise
> > > when you're using gpm or X), no retyping, no vi.
> >
> > Command Substitution:
> >
> >     $ cat <<EOF >cmd.lst
> >     df
> >     ls
> >     uptime
> >     EOF
> >
> >     $ $( grep df cmd.lst )
> >
> > QED.
> 
> Not quite QED (tho quite close). What I'm looking for is how to edit 
> and execute an EXISTING cmd.lst. Sorry if I'm missing something 
> perfectly obvious. Hope this is the penultimate strand on this thread.

Which gets us back to what I believe was the first suggestion I made.

You can recall commands from your history with <ctrl>-R (if emacs-mode
line editing is enabled)  or other history manipulation commands.

You can edit same on the command line using emacs or vi command-line
editing keys.

You can pull the whole schmeer into an editing session from vi mode with
<esc>-v.

There is the 'fc' "fix-command" shell built-in in bash which allows you
to specify a command to command you want to modify.  man bash for more
info.

There is a slew of command-history modification functions, most of which
are like my exes:  well known once but largely forgotten.  Jerry Peek
has a really neat shell tutorial online, see
http://www.jpeek.com/talks/svlug_19991103/index.html

I still don't understand why these don't fit your needs.

A close reading of the bash man page is very strongly recommended.

-- 
Karsten M. Self <kmself@ix.netcom.com>    http://kmself.home.netcom.com/
 What part of "Gestalt" don't you understand?       There is no K5 cabal
  http://gestalt-system.sourceforge.net/         http://www.kuro5hin.org

Attachment: pgps68JCn0V_K.pgp
Description: PGP signature


Reply to: