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-lines" then the line numbers should be omitted which are not shown in the diff.
From the manual: -N or --LINE-NUMBERS Causes a line number to be displayed at the beginning of each line in the display. You can also toggle line numbers without quitting less by typing -N . It is possible to toggle any of less's command line options in this way.
On Unix-like operating systems, the diff command analyzes two files and prints the lines that are different. In essence, it outputs a set of instructions for how to change one file to make it identical to the second file.
Below code can be used display uncommon fields in two files, side by side.
sdiff -l file1 file2 | cat -n | grep -v -e '($'
Below code will display common fields along with line numbers in the output.
diff -y file1 file2 | cat -n | grep -v -e '($'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With