473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

parse unix-style difference reporting

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
Jul 19 '05 #1
4 4932
In article <bs**********@avnika.corp.mot.com>,
"Liang" <le*********@hotmail.com> 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, ba****@alum.mit.edu
Arlington, MA
Jul 19 '05 #2
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: jl******@earthlink.net, jl******@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/

Jul 19 '05 #3
In comp.software.config-mgmt Liang <le*********@hotmail.com> 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
Jul 19 '05 #4
>
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, ba****@alum.mit.edu
Arlington, MA

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
4
by: rkoida | last post by:
Hello evryone I am a newbie to python. I have a makefile which i can compile in UNIX/LINUX, But i I am planning to write a python script which actually does what my MAKEFILE does. The make file...
0
by: John M. Lembo | last post by:
I am using Perl to parse a text file and output to another file. The text file has data on Unix virtual memory (vmstat) and I want to delete lines that I don't want and output lines that I want to...
6
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
2
by: Vittal | last post by:
Hello All, I am trying to compile my application on Red Hat Linux 8 against gcc 3.2.2. Very first file in application is failing to compile. I tried compiling my application on Linux 7.2...
19
by: linzhenhua1205 | last post by:
I want to parse a string like C program parse the command line into argc & argv. I hope don't use the array the allocate a fix memory first, and don't use the memory allocate function like malloc....
22
by: nick | last post by:
#include <stdio.h> #define BALANCE 5000 int main(){ int balance = BALANCE; return 0; } when i compile it, an error occurs,what's happen?
2
by: Li-fan Chen | last post by:
Hi, We find ourselves in the unenviable position of creating an email reader, may I ask how we best parse incoming messages? Ideally we would point the parser at a email stored in a POP3--grab...
3
by: cgiatras | last post by:
I wanted to know if there was a C library out there to parse e-mails / attachments? what I am trying to do is an e-mail is sent to email@domain.com and that will be sent to this c program. It...
9
by: Krumble Bunk | last post by:
Hi all, I am trying my hands at writing a shell for unix. A very rubbish shell, but nonetheless, I come to a point where I am confused. I would like to have something like shellstop xyz ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.