[comp.unix.questions] Append file commands for Unix & ex/vi

lane@dalcs.UUCP (John Wright/Dr. Pat Lane) (01/11/87)

Is there a way to append a range of text to a file from vi/ex (as opposed
to 'w' which writes or over-writes)?

Are there simple Unix commands to append files with syntax and action similar
to 'cp' and 'mv'.  I developed the following alii and I'm wondering if they
are necessary:
	alias append cat !:1 >>!:2`test -d !:2 && echo /!:1`
	alias tack append !:1 !:2 && rm !:1

	(I would accept suggestions on a better name for the latter!)

Many thanks.

-- 
John Wright      //////////////////      Phone:  902-424-3805  or  902-424-6527
Post:  c/o Dr Pat Lane, Biology Dept, Dalhousie U, Halifax, NS, Canada, B3H-1J4
Ean/Bitnet: lane@cs.dal.cdn    Arpa: lane%cs.dal.cdb%ubc.csnet@csnet-relay.arpa
Uucp:{seismo,watmath,utai,garfield}!dalcs!lane  Csnet:lane%cs.dal.cdn@ubc.csnet	

ucscb.bitbug@ucbvax.Berkeley.EDU (01/12/87)

>From: "John Wright/Dr. Pat Lane" <lane@dalcs.uucp>
>Date: 11 Jan 87 15:15:09 GMT
>Keywords: append command unix ex vi
>To:       info-unix@brl-sem.arpa

>
>
>Is there a way to append a range of text to a file from vi/ex (as opposed
>to 'w' which writes or over-writes)?

Yes. In escape mode, type

!<range>cat >> file<CR>

Where <range> is ! for present line,
		 G for to end of file,
		 } to end of paragraph, etc.


>
>Are there simple Unix commands to append files with syntax and action similar
>to 'cp' and 'mv'.  I developed the following alii and I'm wondering if they
>are necessary:
>	alias append cat !:1 >>!:2`test -d !:2 && echo /!:1`
>	alias tack append !:1 !:2 && rm !:1
>
>	(I would accept suggestions on a better name for the latter!)

With the append (>>) operator in sh and csh, I don't see why you would want
or need a command to append one file to another. The syntax it appears you
want is "append file1 file2". Such a program would be quite easy to write.
You already have.

jc@piaget.UUCP (John Cornelius) (01/12/87)

In article <2333@dalcs.UUCP> lane@dalcs.UUCP (John Wright/Dr. Pat Lane) writes:
:
:Is there a way to append a range of text to a file from vi/ex (as opposed
:to 'w' which writes or over-writes)?
:
:Are there simple Unix commands to append files with syntax and action similar
:to 'cp' and 'mv'.  I developed the following alii and I'm wondering if they
:are necessary:
:	alias append cat !:1 >>!:2`test -d !:2 && echo /!:1`
:	alias tack append !:1 !:2 && rm !:1
:
:	(I would accept suggestions on a better name for the latter!)
:
:Many thanks.

The VI document suggests that "Sometimes it is necessary to
append iformation onto the end of a file that already exists.
For example, if you wanted to append several lines to the file
'save', you could use the command:

	:12,25w >>save

"The editor will display the name of the file 'save', the number
of lines, and the number of characters added to the file."

-- 
John Cornelius
(...!sdcsvax!piaget!jc)

romwa@utcs.uucp (01/13/87)

The simplest way I know of to write a range of text out to
the end of another file is:

1) Bring up last line mode (the colon).
2) Type "n,nw !cat >> filename"

where "n,n" is the line range of text to be written.

I believe this is a not-to-obvious feature of vi.

Mark T. Dornfeld
Royal Ontario Museum
Toronto, Ontario

utcs!rom!mark

boykin@custom.UUCP (01/14/87)

>Is there a way to append a range of text to a file from vi/ex (as opposed
>to 'w' which writes or over-writes)?

Both UNIX and PC/VI accept the command:

	:[1,$]w>> filename

which will append the specified line range, with the entire buffer being
the default, to the named file.  Commands which use the shell escape, such
as:
	:[!,$]w !cat >> file

will work, but are very inefficient; why invoke another process when
VI can do it for you?!?

Joe Boykin
Custom Software Systems
{decvax, mit-eddie, tektronix}!frog!custom!boykin

forrest@blia.BLI.COM (Jon Forrest) (01/14/87)

Try

1,5w >> file

(Of course replace the range with your own.)

Jon Forrest
mtxinu!ucbvax!blia!forrest

broome@daffy.UUCP (01/15/87)

You don't need to use aliases or even shell commands -- to append text to 
an existing file in vi, simply say "'a,'b w >> file" ...

This assumes that you've marked the range with "a" & "b", but you can also
use the other usual ways of naming lines (numbers, ".", "$", etc.) 
You can also leave out the range altogether and append the entire current
file onto the other file, like so: "w >> file".

Hope that helps...


==============================================================================
Jonathan C. Broome                         Abel Image Research, Hollywood, Ca.

        {cogsci.berkeley.edu, randvax, styx} \
                                              !abel!{broome,root,uucp,etc ...}
          {celerit, culler, omnilax, vortex} /
==============================================================================

det@herman.UUCP (Derek Terveer) (01/15/87)

In vi (and i'm sure that ex works the same way) to append do a:

:23,45w>>file

to append lines 23 through 45 to file: file