Skip to content

Instantly share code, notes, and snippets.

@robjwells
Created October 17, 2013 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robjwells/7021223 to your computer and use it in GitHub Desktop.
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
#!/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'])
#!/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