Last active
December 15, 2015 18:19
-
-
Save jimr/5302878 to your computer and use it in GitHub Desktop.
Python script for finding the first difference between two lines. Useful for (e.g.) diffing minified JS. Usage: git diff -p some/minified/file.js | grep "^[+-]" | tail -n 2 | python diff.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import fileinput | |
lines = list(fileinput.input()) | |
if len(lines) != 2: | |
raise Exception("Input must be a pair of lines to diff") | |
for i, (char1, char2) in enumerate(zip(*lines)): | |
if char1 != char2: | |
print i, char1, char2 | |
if i > 0: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment