Skip to content

Instantly share code, notes, and snippets.

@orliesaurus
Last active August 29, 2015 13:57
Show Gist options
  • Save orliesaurus/9431320 to your computer and use it in GitHub Desktop.
Save orliesaurus/9431320 to your computer and use it in GitHub Desktop.
Remove Escape Chars from text file in Python
#Usage: python thisfile.py "path/to/file.txt" > cleanfile.txt
import re
import sys
with open(sys.argv[1]) as fp:
for line in fp:
newline = re.sub(r'\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]', "", line)
print newline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment