![]()
A little while ago, I wrote:
> same
> same
> | different
> | different
> same
> same
>
> Can anyone point me to a utility which does this?
Thanks to everyone who wrote and told me about 'diff', which wasn't quite
what I meant, and thanks particularly to Cal Jewell and Richard Mathews,
who pointed out how to lean on diff to get it to do what I want and sent
along sed scripts to tweak the output. I settled on the following:
#!/usr/local/bin/perl
# diff-faq v. 4 Nov 94 Dave Schweisguth <dcs@proton.chem.yale.edu>
# Produces a unidiff-like comparison of two files, ignoring deletions.
# Sections where differences are to be marked must begin with (at least)
# two spaces.
($whatami = $0) =~ s|.*/||; # `basename $0`
die "$whatami: Specify two input files.\n" unless @ARGV == 2;
@diff = `diff -cw100000 @ARGV`;
if (($status = $? >> 8) == 2) {
die "$whatami: diff exited unhappily.\n";
} elsif ($status == 0) { # No differences; just cat $ARGV[1]
open(NEW, $ARGV[1]) || die "$whatami: Couldn't open $ARGV[1]!?!\n";
print <NEW>;
close;
} else { # Differences
1 until shift(@diff) =~ /^--- \d+(,\d+)? ----/;
foreach (@diff) {
s/^([!+]) /$1 / || s/^[! ] //;
print;
}
}
I thought requiring the lines which I wish to mark to begin with two spaces
(that is, having a >= two-space left margin for real text but not headers,
etc.) was the best way to produce nicely readable output without messing
with headers, etc. But that's a detail; the real point is the lines-of-
context codicil to the -c option to diff.
Cheers,
-- | Dave Schweisguth Internet: dcs@proton.chem.yale.edu MIME spoken here | | Yale Depts. of MB&B & Chemistry Phone: 203-432-5208 Fax: 203-432-6144 | | For complying with the NJ Right To Know Act: Contents partially unknown. |
[
Usenet Hypertext FAQ Archive |
Search Mail Archive |
Authors |
Usenet
]
[
1993 |
1994 |
1995 |
1996 |
1997
]
![]()
© Copyright The Landfield Group, 1997
All rights reserved