Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # $Id: pickrandom.py,v 1.2 2012/11/15 21:50:17 elias Exp $
- import sys
- import fileinput
- import random
- if len(sys.argv) < 2:
- sys.stderr.write('Benutzung: %s [stichprobe] [dateinamen]' % (sys.argv[0],))
- sys.exit(1)
- files = sys.argv[2:]
- try:
- picklines = int(sys.argv[1])
- except ValueError:
- sys.stderr.write('Erster Parameter muss eine Zahl sein\n')
- sys.exit(1)
- infiles = fileinput.input(files)
- lines = [i for i in infiles]
- for line in random.sample(lines, picklines):
- sys.stdout.write(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement