Unix Programming - simple question about using diff

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2007 > simple question about using diff





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author simple question about using diff
Lawson English

2007-11-02, 7:25 pm

Very simple question, I hope. If I have two files or source trees, and I
want to have a count of the number of lines of code that have changed
from one to the next version, what is the command string to obtain this
info using diff? Or should I be using another utility instead?

Thanks


Lawson English
Eric Sosman

2007-11-02, 7:25 pm

Lawson English wrote On 11/02/07 17:04,:
> Very simple question, I hope. If I have two files or source trees, and I
> want to have a count of the number of lines of code that have changed
> from one to the next version, what is the command string to obtain this
> info using diff? Or should I be using another utility instead?


One way would be to run an ordinary diff and pipe the
output through egrep with the -c option:

diff file1 file2 | egrep -c '^[<>]'

Note that this will count each "change" twice, once as a
deletion and once as an insertion. Simple deletions and
insertions will be counted once each. Big relocations of
a block of code from one place to another will be counted
as a bunch of deletions and a bunch of insertions. What
I'm getting at is that "change count" is not a rigorously-
defined notion.

--
Eric.Sosman@sun.com

Lawson English

2007-11-02, 7:25 pm

Eric Sosman wrote:
> Lawson English wrote On 11/02/07 17:04,:
>
> One way would be to run an ordinary diff and pipe the
> output through egrep with the -c option:
>
> diff file1 file2 | egrep -c '^[<>]'
>
> Note that this will count each "change" twice, once as a
> deletion and once as an insertion. Simple deletions and
> insertions will be counted once each. Big relocations of
> a block of code from one place to another will be counted
> as a bunch of deletions and a bunch of insertions. What
> I'm getting at is that "change count" is not a rigorously-
> defined notion.
>



KK this gives me at least something ballparkish to look at though. And
in the context, I doubt if there are many relocations of large blocks of
code. (I'm trying to get a handle on how much the Second Life client is
changed from release to release ).


Lawson


Stephane CHAZELAS

2007-11-03, 7:28 am

2007-11-02, 14:04(-07), Lawson English:
> Very simple question, I hope. If I have two files or source trees, and I
> want to have a count of the number of lines of code that have changed
> from one to the next version, what is the command string to obtain this
> info using diff? Or should I be using another utility instead?

[...]

See the diffstat utility by Thomas Dickey.

man> This program reads the output of diff and displays a histogram of the
man> insertions, deletions, and modifications per-file. Diffstat is a pro-
man> gram that is useful for reviewing large, complex patch files. It reads
man> from one or more input files which contain output from diff, producing
man> a histogram of the total lines changed for each file referenced. If
man> the input filename ends with .bz2, .Z or .gz, diffstat will read the
man> uncompressed data via a pipe from the corresponding program.
man>
man> Diffstat recognizes the most popular types of output from diff:
man>
man> unified
man> preferred by the patch utility.
man>
man> context
man> best for readability, but not very compact.
man>
man> default
man> not good for much, but simple to generate.

--
Stéphane
Lawson English

2007-11-04, 1:34 am

Stephane CHAZELAS wrote:
> 2007-11-02, 14:04(-07), Lawson English:
> [...]
>
> See the diffstat utility by Thomas Dickey.
>
> man> This program reads the output of diff and displays a histogram of the
> man> insertions, deletions, and modifications per-file. Diffstat is a pro-
> man> gram that is useful for reviewing large, complex patch files. It reads
> man> from one or more input files which contain output from diff, producing
> man> a histogram of the total lines changed for each file referenced. If
> man> the input filename ends with .bz2, .Z or .gz, diffstat will read the
> man> uncompressed data via a pipe from the corresponding program.
> man>
> man> Diffstat recognizes the most popular types of output from diff:
> man>
> man> unified
> man> preferred by the patch utility.
> man>
> man> context
> man> best for readability, but not very compact.
> man>
> man> default
> man> not good for much, but simple to generate.
>


Thanks much.

L.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com