simple question about using diff - Unix

This is a discussion on simple question about using diff - Unix ; 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 ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: simple question about using diff

  1. simple question about using diff

    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

  2. Re: simple question about using diff

    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


  3. Re: simple question about using diff

    Eric Sosman wrote:
    > 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.
    >



    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



  4. Re: simple question about using diff

    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

  5. Re: simple question about using diff

    Stephane CHAZELAS wrote:
    > 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.
    >


    Thanks much.

    L.

+ Reply to Thread