How do I find and highlight differences between two text files? [closed]

Multi tool use
How do I find and highlight differences between two text files? [closed]
Our team is a small group of data analysts doing report development in a variety of languages including mostly SAS and Python. We are limited in what we can install. As such, we don't have a formalized version control system in place but can manually handle version controls, forking, merging, etc. since we typically manage our own scripts from start to finish. Now, however, I am working in parallel with a new member of the team and finding it increasingly challenging to manage different versions.
I am looking for a simple way, using Python (3.6 via Anaconda) or Windows (7 or 10), to find the line-by-line differences between two files. I want to see the contents of both files with the differences highlighted.
The files are stored in a shared folder and will get updated by multiple people in parallel, but as mentioned, there is no formal version control system. I know there are other utilities to install, and I know I could create something on my own, but I want something that doesn't need to be installed and doesn't need to be a custom utility.
This question appears to be off-topic. The users who voted to close gave this specific reason:
Check out difflib. I know you said you didn't want to add any software, but git is also really handy for diffing.
– chet-the-wizard
Jun 29 at 20:27
@chet-the-wizard I wanted to use git, but git has more overhead than made sense given that I'd probably be the only one willing to install it and I wanted others to be able to use it. I ended up using difflib.
– Eliot K
Jun 29 at 20:43
1 Answer
1
You are welcome to use the difflib library. It even has a command line interface.
The file you need to run, diff.py
, resides in Toolsscripts
under your local python installation.
diff.py
Toolsscripts
These are the parameters:
-c Produce a context format diff (default)
-u Produce a unified format diff
-m Produce HTML side by side diff (can use -c and -l in conjunction)
-n Produce a ndiff format diff
-l Set number of context lines (default 3)
fromfile
tofile
Producing an HTML will probably yield (pun intended) the best results.
This is the answer I was expecting, but I couldn't find it explicitly given anywhere else -- all the other
difflib
references were buried.– Eliot K
Jun 29 at 20:39
difflib
@EliotK Glad I could help :-)
– Bharel
Jun 29 at 20:40
use difflib library. find more about it docs.python.org/2/library/difflib.html
– TheOne
Jun 29 at 20:25