Skip to content

Instantly share code, notes, and snippets.

@lukecampbell
Created January 22, 2016 13:42
Show Gist options
  • Save lukecampbell/00d1698d89a9ae877a12 to your computer and use it in GitHub Desktop.
Save lukecampbell/00d1698d89a9ae877a12 to your computer and use it in GitHub Desktop.
Replaces terminal escape characters with a space
#!/usr/bin/env python
import sys
def valid_character(i):
return ord(i) < 128 and (ord(i) > 31 or ord(i) == 10 or ord(i) == 0)
def main(args):
'''
Replaces terminal escape characters with a space
'''
with open(args.path, 'r') as f:
buf = f.read()
fixed = ''.join([i if valid_character(i) else ' ' for i in buf])
with open(args.path, 'w') as f:
f.write(fixed)
return 0
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser(description=main.__doc__)
parser.add_argument('path', help='Path to file to be fixed')
args = parser.parse_args()
sys.exit(main(args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment