Skip to content

Instantly share code, notes, and snippets.

@xavivars
Created July 20, 2012 18:56
Show Gist options
  • Save xavivars/3152572 to your computer and use it in GitHub Desktop.
Save xavivars/3152572 to your computer and use it in GitHub Desktop.
Pipes stdin to stdout removing the words that appear in a given file
#!/usr/bin/python
import sys
# comprovem el parametre
if len(sys.argv)<2:
print >> sys.stderr, "ERROR: Cal utilitzar un fitxer."
# carreguem el diccionari correcte en memoria
dicc = {}
f = open(sys.argv[1], 'r')
for line in f.readlines():
dicc[line.strip()]=1
# llegim i comprovem l'entrada estandar
for linea in sys.stdin:
if not dicc.has_key(linea.strip()):
print linea;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment