Get line numbers of differences in two files when running diff for two files on Windows

In order to verify the code after changing the existing source file, we look only at the lines of code that have been changed in these source files.
After I make changes to the source files in the repository, I have to transfer the lines of code that have been changed in the source file before we do our peer-to-peer reviews.

I can see the visual diff using WinMerge, and I'm happy with what it does for me, but the only requirement for my employees is just to know the file name and line numbers that need to be reviewed,

Is there a way to get only line numbers of a modified file? File types will be text source files such as Javascript, Java, XML, XSL, etc.

Sample Files -

foo (new version):

a b c d e f g h i j k 

foo (old version):

 a b C d h i k 

The result I'm looking for:

 foo: 3, 5-7, 10-11 

OR

 foo: 3 5-7 10-11 

I am sure some programs allow this. I just can't find it. Any suggestions? I am currently using WinMerge, but any program that runs on Windows will be fine with me. It would be preferable if the software is open source or free.

EDIT: GNU DiffUtils is close to what I want, but does not exactly match my needs. Looking at the command line options, I see "-q" (or "--brief") as a simplified diff, but it's too simple. Output:

 C:\Program Files\GnuWin32\bin>diff.exe -q foo1.txt foo2.txt Files foo1.txt and foo2.txt differ 

Normal output:

 C:\Program Files\GnuWin32\bin>diff.exe foo1.txt foo2.txt 3c3 < c --- > C 5,7d4 < e < f < g 10,11c7 < j < k --- > k \ No newline at end of file 

diff -u output:

 C:\Program Files\GnuWin32\bin>diff.exe -u foo1.txt foo2.txt --- foo1.txt 2010-11-09 15:47:12.447916000 -0600 +++ foo2.txt 2010-11-09 15:47:36.129954700 -0600 @@ -1,11 +1,7 @@ a b - c + C d - e - f - g h i - j - k + k \ No newline at end of file 

I am looking for something more informative than diff -q, but less informative than diff -u and diff. Any different ninjas who know different options to solve this?

I will always compare a new, recently modified file with an older one. I need only those things that need to be viewed in a new file.

+4
source share
4 answers

GNU DiffUtils is an open source, free and Windows port .

+3
source

Save the first file as x.txt and the second as y.txt

Then run:

diff -i --unchanged-line-format = "Ā„" --new-line-format = ":% dn:% L" y.txt x.txt | perl -pe 's / Ā„ / \ n / g' | perl -pe '$ count ++; if ($ _! ~ / ^ \ n $ /) {print "$ count \ t";} '

+2
source

It is not known about the standard method for Windows, but I use the file comparison function for Textpad to do this, and this is pretty good.

+1
source

Windows is native. Our SD Smart Differencer does not produce delta by row, but by program structure and exactly corresponds to the line / column-row / column and type of program the object that was edited. It is compared by analyzing the source text and using the code structure for comparison. Deltas are described in terms of actions of interest to programmers: Insert, Replace, Delete, Substitute.

Here is an example:

 Java~Java1_5 SmartDifferencer Version 1.1.1 Copyright (C) 2009 Semantic Designs, Inc; All Rights Reserved; SD Confidential Powered by DMS (R) Software Reengineering Toolkit *** Parsing file C:/DMS/Domains/Java/Java1_5/Analyzers/SmartDifferencer/Tests/diff1_before.java ... *** Parsing file C:/DMS/Domains/Java/Java1_5/Analyzers/SmartDifferencer/Tests/diff1_after.java ... *** Creating suffix tree ... *** Determining maximal pairs ... *** Sorting maximal pairs ... *** Determining differences ... *** Printing edits ... a12.5 I s12.5-12.57:field_declaration a179.9 I s185.9-185.71:executable_statement a193.5 I s201.9-203.9:executable_statement a272.13 I t279.13-280.33f267.13-268.30[267.17'lineNum'~>279.17'endLineNum',268.17'columnNum'~>280.17'endColumnNum']:statement_sequence_member,statement_sequence_member a340.68 I s352.68-352.68:',' s352.70-352.70:INTEGER s352.71-352.71:',' s352.73-352.73:INTEGER a423.13 I t436.13-509.38f450.17-518.35[482.17'hlevel'~>468.13'endLineNum',518.17'hname'~>509.13'endColumnNum']:executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement a423.84 I s513.84-513.84:',' s513.86-513.95:IDENTIFIER s513.96-513.96:',' s513.98-513.109:IDENTIFIER s424.13-424.59:expression_statement S s514.25-514.47:expression_statement s429.13-429.64:local_variable_declaration S s515.25-515.87:local_variable_declaration s430.13-430.71:executable_statement f431.13-431.69[431.13'lineString'~>79.9'config',431.26'lineString'~>79.18'config',431.47'indexOfSpace'~>79.35'end_index']t79.9-79.56:executable_statement s432.13-432.51:executable_statement D a516.25 a433.13 I s516.25-519.25:executable_statement n433.13-439.13:executable_statement s433.13-433.14:'if' s433.16-433.16:'(' s433.17-433.30:relational_expression s433.31-433.31:')' s433.33-433.45:executable_statement s434.13-434.16:'else' n434.18-439.13:block s434.18-434.18:'{' n435.17-438.49:statement_sequence f435.17-435.71[435.17'lineString'~>79.9'config',435.28'lineString'~>79.18'config',435.49'indexOfSpace'~>79.35'end_index']t79.9-79.56:executable_statement s436.17-436.28:executable_statement s437.17-437.51:executable_statement s438.17-438.49:executable_statement s439.13-439.13:'}' D a516.25 a442.13 I s520.25-520.54:executable_statement 

High-level editing actions: "I", "S", "R" and "D", with detailed information about what was added, inserted or deleted on the left or right side of the I / S / R / D character with precision to the line. For example, in line 12 of column 5, the field declaration was ā€œIā€ nserted, just in line 12 from column 5 to column 57. On line 272, the code block was ā€œIā€ nserted from lines 279-280 with the lineNum identifier being replaced with endLineNum. On line 424 in the second file, the expression operator was "S", replaced by one originally from line 514. More information on the website.

You can easily remove unnecessary details (for example, the following characters: "and inside []) if you want something like Perl.

+1
source

All Articles