Last active
November 9, 2016 10:41
-
-
Save techtonik/c86f0ea6a86ed3f38893 to your computer and use it in GitHub Desktop.
Strip trailing whitespace from file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
"""\ | |
strip trailing whitespace from file | |
usage: stripspace.py <file> | |
code is placed into public domain | |
""" | |
import sys | |
if len(sys.argv[1:]) != 1: | |
sys.exit(__doc__) | |
content = '' | |
outsize = 0 | |
inp = outp = sys.argv[1] | |
with open(inp, 'rb') as infile: | |
content = infile.read() | |
with open(outp, 'wb') as output: | |
for line in content.splitlines(): | |
newline = line.rstrip(" \t") | |
outsize += len(newline) + 1 | |
output.write(newline + '\n') | |
print("Done. Stripped %s bytes." % (len(content)-outsize)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment