#!/usr/bin/env python f = open('patterns.txt') out = None for line in f: line = line.rstrip('\r\n') if line.startswith(' - '): print >> out, '