Python script to split a text file by even or odd numbers
written a short script to split a file into even or odd line numbers
#!/usr/bin/python
## loop do something to each line of input file
## changed to write the even line numbers to a file
## and the odd line numbers to another
## note that even numbers start with line 0 (not 1!)
## usage: sort-even-odd.py inputfile
## written by kevinl @ kevinl.wordpress.com
import sys
def isodd(n):
return bool(n%2)
input=open(sys.argv[1], 'r')
L=input.readlines()
evenout=open('evenout', 'w')
oddout=open('oddout','w')
for linecount in range(len(L)):
if isodd(linecount):
oddout.write(L[linecount])
else:
evenout.write(L[linecount])
#print "line number is " + str(linecount)