-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveColours
More file actions
executable file
·45 lines (32 loc) · 1.12 KB
/
Copy pathremoveColours
File metadata and controls
executable file
·45 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
################################################################################
"""
Quick script to remove ANSI colours from output for reading in vim.
Run the script with filename as input, output will have _vim.
"""
__title__ = "removeColours.py"
__author__ = "Sam Hall"
__email__ = "[email protected]"
################################################################################
from messages import Messages
import sys
import os
# Global messenger object.
#msg = Messages([__title__,
#'Remove ANSI colours for reading log file in vim.'])
msg = Messages()
def main(filename):
global msg
msg.info('Input file: %s' % filename)
ext = filename.split('.')[-1]
filename_new = filename.replace('.%s' % ext, '_vim.%s' % ext)
msg.info('Output file: %s' % filename_new)
cmd = "cat -v %s|perl -lane 's/\^\[\[\d+(;\d+)*m//g; print' > %s"
cmd = cmd % (filename, filename_new)
msg.info(cmd)
os.system(cmd)
msg.foot()
################################################################################
if __name__ == "__main__":
if len(sys.argv) == 2:
main(sys.argv[1])