Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > parse unix-style difference reporting

Reply
Thread Tools

parse unix-style difference reporting

 
 
Liang
Guest
Posts: n/a
 
      12-30-2003
Hi all,

I want to diff two files or two versions of one file, and parse the output
to find a summary of how many lines of replacement/addition/deletion in the
two files.

Known from diff/cleardiff, the output has a style like:
15a16, 15,17d3, 18c19,21 etc.

Anyone know how to parse these output to generate a summary?

Thanks in advance,
Liang


 
Reply With Quote
 
 
 
 
Barry Margolin
Guest
Posts: n/a
 
      12-30-2003
In article <bsql5f$gsk$(E-Mail Removed)>,
"Liang" <(E-Mail Removed)> wrote:

> Hi all,
>
> I want to diff two files or two versions of one file, and parse the output
> to find a summary of how many lines of replacement/addition/deletion in the
> two files.
>
> Known from diff/cleardiff, the output has a style like:
> 15a16, 15,17d3, 18c19,21 etc.
>
> Anyone know how to parse these output to generate a summary?


You can use "diff -c" and count the number of "<", ">", and "!" lines.
Or use the "comm" command and count the number of lines.

--
Barry Margolin, http://www.velocityreviews.com/forums/(E-Mail Removed)
Arlington, MA
 
Reply With Quote
 
 
 
 
Jonathan Leffler
Guest
Posts: n/a
 
      12-30-2003
Liang wrote:
> I want to diff two files or two versions of one file, and parse the output
> to find a summary of how many lines of replacement/addition/deletion in the
> two files.
>
> Known from diff/cleardiff, the output has a style like:
> 15a16, 15,17d3, 18c19,21 etc.
>
> Anyone know how to parse these output to generate a summary?


It isn't very hard to work it out, is it?

Each item conceptually has four numbers and an operation code:

N1,N2 op N3,N4

When there is just one number on one side of the operation, the values
N1 and N2, or N3 and N4, are the same.

Inserts are easy: there's always a single number on the LHS, and the
number of lines inserted is N4-N3+1.

Similarly, deletes are easy: there's always a single number on the RHS
of the operator, and the number of lines deleted is N2-N1+1.

Number of lines replaced has two parts to the value - the number of
lines removed and the number replacing the removed lines. Depending
on your viewpoint, you can either choose to count the two values
separately (number removed NR = N2-N1+1, number inserted NI =
N4-N3+1), or you can be cleverer about the calculation and decide that
when NR > NI, then you have NI changed lines and NR-NI deleted lines,
and that when NR < NI, you have NR changed lines and NI-NR inserted
lines. When NR = NI, you have NR (or NI) changed lines, of course.

That took me five minutes to think and type - how long would it have
taken you to do it? (And cross-posted too?)

--
Jonathan Leffler #include <disclaimer.h>
Email: (E-Mail Removed), (E-Mail Removed)
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/

 
Reply With Quote
 
Thomas Dickey
Guest
Posts: n/a
 
      12-30-2003
In comp.software.config-mgmt Liang <(E-Mail Removed)> wrote:
> Hi all,


> I want to diff two files or two versions of one file, and parse the output
> to find a summary of how many lines of replacement/addition/deletion in the
> two files.


http://invisible-island.net/diffstat/

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
 
Reply With Quote
 
Liang
Guest
Posts: n/a
 
      12-31-2003
>
> You can use "diff -c" and count the number of "<", ">", and "!" lines.
> Or use the "comm" command and count the number of lines.
>

marvellous! this is the simplest solution.

Happy new year!

> --
> Barry Margolin, (E-Mail Removed)
> Arlington, MA



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
Reporting line number of parse exception? rolf@squarebox.co.uk XML 4 06-25-2005 03:18 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Crashes and Netscape Reporting Stuart Firefox 16 02-07-2004 01:55 AM



Advertisments