Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os,sys
- if len(sys.argv) < 3:
- print "Usage: %s <source file> <percentage>" % sys.argv[0]
- exit(1)
- if not os.path.exists(sys.argv[1]):
- print "Provide a file from wich to extract the sample"
- exit(1)
- if not (int(sys.argv[2]) < 100 and int(sys.argv[2]) > 1):
- print "Provide a percentage of the sample to take (a number between 1 to 100)"
- exit(1)
- srcfile=sys.argv[1]
- percentage=float(sys.argv[2])
- nlines=0
- sf=open(srcfile,"r")
- nlines=sum(1 for _ in sf)
- nresult=int((float(nlines)*(float(percentage)/100.0)))
- step=nlines/nresult
- sf.seek(0)
- i=0
- for line in sf.readlines():
- i+=1
- if (i%step) == 0:
- print line.strip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement