wytnij_wiele.py 628 Bytes
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys

def get_lines(words, reverse):
  first = True
  cut = False
  lines = []
  for line in sys.stdin:
    if first:
      word = line.split('\t')[0].decode('utf-8')
      cut = (word in words) != reverse
      first = False
    if cut:
      lines.append(line)
    if line == '\n':
      first = True
  return lines

if __name__ == '__main__':
  reverse = len(sys.argv) > 2 and sys.argv[2] == '-r'
  with open(sys.argv[1]) as words_file:
    words = [line.strip().decode('utf-8') for line in words_file]
  lines = get_lines(words, reverse)
  sys.stdout.write(''.join(lines))