[net.unix] A question concerning diff

billw@wolf.UUCP (Bill Wisner) (09/03/86)

Many times, I have wondered privately if there is an answer to this problem;
but have gotten no satisfactory answer. Thus, I take this dumb question to the
net:

Is there a program, command, anything, that will take two files
{
	1. An old text file
	2. A "diff" format file
}
and make the changes listed in #2 on #1 and create file #3, the new text file?
-- 
Bill Wisner
..ihnp4!jack!wolf!billw

Property is theft.				  -- P. J. Proudhon
Property is liberty.				  -- P. J. Proudhon
Property is impossible.				  -- P. J. Proudhon
Consistency is the hobgoblin of small minds. -- Ralph Waldo Emerson

rob@ptsfb.UUCP (Rob Bernardo) (09/03/86)

In article <194@wolf.UUCP> billw@wolf.UUCP (Bill Wisner) writes:
>Is there a program, command, anything, that will take two files
>and make the changes listed in #2 on #1 and create file #3, the new text file?

Absolutely. See the -e and -f options of diff(1).
-- 
Rob Bernardo, San Ramon, CA    (415) 823-2417    {ihnp4|dual|qantel}!ptsfa!rob

ark@alice.UucP (Andrew Koenig) (09/04/86)

> Is there a program, command, anything, that will take two files
> {
>	1. An old text file
>	2. A "diff" format file
> }
> and make the changes listed in #2 on #1 and create file #3, the new text file?

diff -e file1 file2    produces a file that when given as input
to `ed' will transform file1 into file2.

guy@sun.uucp (Guy Harris) (09/04/86)

> >Is there a program, command, anything, that will take two files
> >and make the changes listed in #2 on #1 and create file #3, the new text
> >file?
> 
> Absolutely. See the -e and -f options of diff(1).

No, that takes two files and produce an "ed" script that will make the
changes mentioned.  It sounds like he may have wanted something that takes
an *existing* "diff" listing, *not* necessarily produced with "diff -e", and
make the changes.

There is, in fact, such a program.  It's called "patch", was written by
Larry Wall, and has been posted either to "net.sources" or "mod.sources" on
various occasions.  It is also supplied as part of the "user contributed
software" with 4.3BSD (although I think the version posted most recently
fixes some bugs that ar in the version that comes with 4.3BSD); the "Bug
Fixes and Changes in 4.3BSD" document says "If you only look at one new
program, this is the one!", and they're right.

It is not only useful for applying fixes supplied in the form of "diff" or
context "diff" listings, it is also useful for applying fixes made to one
version of a program to other versions (e.g., if you fix a bug in Version 3
of something, it can be used for applying the fix to Version 2.2; just
"diff" the unfixed and fixed Version 3 source and then use "patch" on the
Version 2.2 file).
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com (or guy@sun.arpa)

rbp@investor.UUCP (Bob Peirce) (09/06/86)

> Is there a program, command, anything, that will take two files
> {
> 	1. An old text file
> 	2. A "diff" format file
> }
> and make the changes listed in #2 on #1 and create file #3, the new text file?
> -- 
> Bill Wisner
> ...ihnp4!jack!wolf!billw

The Sys III manual for diff(1) claims that diff -e file1 file2 will
produce "a script of a, c and d commands for the editor ed, which will
recreate file2 from file1."

I haven't tried it, but I assume something like the following might work.

	ed file1 < diffs > file 2
-- 

	 	    Bob Peirce, Pittsburgh, PA
	    uucp: ...!{allegra, bellcore, cadre, idis}
	  	     !pitt!darth!investor!rbp
			    412-471-5320

	    NOTE:  Mail must be < 30K  bytes/message

rbp@investor.UUCP (Bob Peirce) (09/07/86)

> > Is there a program, command, anything, that will take two files
> > {
> > 	1. An old text file
> > 	2. A "diff" format file
> > }
> > and make the changes listed in #2 on #1 and create file #3, the new text file?
> 
> The Sys III manual for diff(1) claims that diff -e file1 file2 will
> produce "a script of a, c and d commands for the editor ed, which will
> recreate file2 from file1."
> 
> I haven't tried it, but I assume something like the following might work.
> 
> 	ed file1 < diffs > file2
> 
> 	 	    Bob Peirce, Pittsburgh, PA

Bad assumption.  The manual also gives the solution.

	(cat diffs; echo '1,$p') | ed - file1 > file2
-- 

	 	    Bob Peirce, Pittsburgh, PA
	    uucp: ...!{allegra, bellcore, cadre, idis}
	  	     !pitt!darth!investor!rbp
			    412-471-5320

	    NOTE:  Mail must be < 30K  bytes/message