Created
October 17, 2013 08:29
-
-
Save robjwells/7021223 to your computer and use it in GitHub Desktop.
copy_diff - Compare two sections of the same file See http://robjwells.com/post/61132555301/solo-diff
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 python3 | |
import os | |
import re | |
import subprocess | |
os.chdir('/tmp') | |
with open(os.environ['BB_DOC_PATH']) as full_file: | |
sub_copy, orig_copy = re.split(r'#{2,} original copy #{2,}', | |
full_file.read(), flags=re.I) | |
with open('bb_orig_copy', 'w') as orig_file: | |
orig_copy = orig_copy.strip() + '\n' | |
orig_file.write(orig_copy) | |
with open('bb_subbed_copy', 'w') as sub_file: | |
sub_copy = sub_copy.strip() + '\n' | |
sub_file.write(sub_copy) | |
subprocess.call(['bbdiff', 'bb_orig_copy', 'bb_subbed_copy']) |
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 python3 | |
from sys import stdin | |
orig = stdin.read() | |
dupe = "{0}\n\n\n\n#### Original Copy ####\n\n\n\n{0}".format(orig) | |
print(dupe) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment