# genpipe.py from grep import grep from uniq import uniq regex = "\w+" L = ''' abcdef xyz Hello, world! $#@%)*@&# foo abcdef bar xyz ''' L = L.split('\n') L.sort() L = list(uniq(grep(L, regex))) print '\n'.join(L)