views:

205

answers:

4

Now my program generates two data files. a.txt and b.txt Take a.txt as an example, it's content just like this:

0,0
0,1
1,0
-3,1
1,-2
1,3
......

b.txt is similar with a.txt.

Now, I hope to find out difference lines count. In other words, for example, if b.txt like this:

0,0
1,1
1,2
-3,1
1,-2
1,3
......

a shell script output 2 as the 2nd and the 3rd lines are different with one number different. How to do this???

I try diff command, however, I cannot get what I want...

Need your kind help..Thanks.

Addition: There are about 10,000 - 100,000 rows for each files. Of course, they have same no. of rows at each time.

+1  A: 

diff seems to be exactly what you want.

#> diff a.txt b.txt
2,3c2,3
< 0,1
< 1,0
---
> 1,1
> 1,2

Is there something more specific you were looking for?

Scottie T
thank you for your kind help.
MaiTiano
when I type as you said, I got this message,grep: unrecognized option '---',
MaiTiano
+4  A: 
diff a.txt b.txt | grep "<" | wc -l
Ivan Krechetov
thanks I forget to count number of "---", thanks Ivan.
MaiTiano
Welcome! Actually, I think you need "<" instead of "---". I've made a correction in the answer.
Ivan Krechetov
+1  A: 

diff may move chunks within a file which is not what you want I think. Here's an alternative:

join -t'\0' -v2 <(cat -n a.txt) <(cat -n b.txt) | wc -l
pixelbeat
+3  A: 

Faced the same problem a while back. What you need is diffstat. Diffstat is part of the GNU diff package and can summarizes diff results:

SYNOPSIS

diffstat reads the output of diff and displays a histogram of the insertions, deletions, and modifications per-file. It is useful for reviewing large, complex patch files.

You can also process the output of diffstat to get summarized results:

diff -u FileA.txt FileB.txt | diffstat -f0 | grep -v files | awk '{ print $3 }'

Where -u is obligatory. You can explore diffstat documentation for options.

Bruno Brant