Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created June 5, 2013 14:53
Show Gist options
  • Save meeuw/5714460 to your computer and use it in GitHub Desktop.
Save meeuw/5714460 to your computer and use it in GitHub Desktop.
called like: python removesorted.py haystack needles, only works on sorted files, remove needles from haystack.
import sys
haystack = open(sys.argv[1])
needles = open(sys.argv[2])
needle = needles.readline()[:-1]
counter = 0
while 1:
hay = haystack.readline()[:-1]
if not hay: break
if hay == needle:
needle = needles.readline()[:-1]
counter = 0
else:
print hay
counter += 1
if counter > 100:
print counter, needle
break
haystack.close()
needles.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment