Skip to content

Instantly share code, notes, and snippets.

@jeroenjanssens
Created June 6, 2014 00:29
Show Gist options
  • Save jeroenjanssens/af091bc6e1dbb8a656c7 to your computer and use it in GitHub Desktop.
Save jeroenjanssens/af091bc6e1dbb8a656c7 to your computer and use it in GitHub Desktop.
Remove header without streaming entire file
#!/usr/bin/env python
# The trick is to overwrite the file with spaces till the first newline.
# Only works if the program that reads it ignores empty lines.
import sys
filename = sys.argv[1]
f = open(filename, "r+b")
n = 0
while f.read(1) != "\n":
n += 1
f.seek(0)
f.write(" " * n)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment