'How to display line numbers in side by side diff in unix?

The scenario is that i have 2 files which i want to diff side by side using the following command with the line numbers:

diff -y file1.txt file2.txt

and

sdiff file1.txt file2.txt

The above command just prints the side by side diff but doesn't display the line numbers. Is there any way to do it ? I searched a lot but couldn't find any solutions. I can't use third party tools FYI. Any genius ideas from anyone ?

Update:

I want the file numbers present of the file itself and not the line numbers generated by piping to cat -n etc.. Lets say, i am doing diff using "--suppress-common-l‌​ines" then the line numbers should be omitted which are not shown in the diff.



Solution 1:[1]

The following command will display the side-by-side output prepended with line numbers for file1.txt and identical lines removed.

sdiff -l file1.txt file2.txt | cat -n | grep -v -e '($'

Solution 2:[2]

sdiff -s <(cat -n file1.txt) <(cat -n file2.txt)

This gives you side-by-side output with line-numbers from the source files.

Solution 3:[3]

I had the same issue and ended up using a graphical tool (diffuse) under fedora 28

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 markpietrus
Solution 2 Mike Titus
Solution 3 user11425287