Skip to content

Instantly share code, notes, and snippets.

@Xennis
Created January 7, 2016 17:15
Show Gist options
  • Save Xennis/dddd1b4ef10f69e9994f to your computer and use it in GitHub Desktop.
Save Xennis/dddd1b4ef10f69e9994f to your computer and use it in GitHub Desktop.
Split a texfiles
import sys
def split_file(filename, num_max_lines=None):
num_lines = 0
with open(filename) as f:
for line in f:
num_lines += 1
sys.stdout.write(line)
if num_max_lines and num_lines >= num_max_lines:
break
if __name__ == '__main__':
argv = sys.argv[1:]
if len(argv) == 1:
split_file(argv[0])
elif len(argv) == 2:
split_file(argv[0], int(argv[1]))
else:
print('Usage: split.py <FILENAME> <NUM-MAX-LINES>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment