Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to show line number in side-by-side diff output?

Tags:

diff

I am using diff with the -y and --suppress-common-lines options and the output is almost perfect except I'd like to see the line numbers of the changes.

Example:

file1:

line a
line b
line c

file2:

line a
line B
line c
line d

command and output:

$ diff -y --suppress-common-lines file1 file2
line b                                                        | line B
                                                              > line d

Is this combination of options possible with diff or do I need another tool?

like image 558
Dave Forgac Avatar asked Dec 02 '11 21:12

Dave Forgac


People also ask

What do the numbers in the line mean in output of diff?

They are line-numbers for the old/new files to help the patch (or similar) program decode the unified-diff. the number before the comma is the line number for the beginning of the chunk. The + and - signs refer to adding and deleting lines, respectively.

Does diff Compare line by line?

The Linux diff command is used to compare two files line by line and display the difference between them. This command-line utility lists changes you need to apply to make the files identical. Read on to learn more about the diff command and its options with easy-to-follow examples.

What is the output of diff?

Output generated by diff is a collection of information of each line within different group types. Further, it gives three options – namely, –line-format, –LTYPE-line-format, and –GTYPE-group-format – for fine control of the output format.


1 Answers

Unfortunately the -y option uses the formatting style internally (as does --LFMT-line-format), you cannot cumulate formatting commands with -y. You cannot obtain from formatting parameters what -y does, so you cannot workaround directly with diff (I checked diff 3.2 source code).

You need to use another tool.

like image 177
armel Avatar answered Sep 20 '22 04:09

armel