I had this same problem several weeks ago in bash, but now I would like a solution in python.
My input looks like this:
^MCopying non-tried blocks... Pass 1 (forwards)^M^[[A^[[A^[[Arescued: 0 B, errsize: 0 B, current rate: 0 B/s
ipos: 0 B, errors: 0, average rate: 0 B/s
opos: 0 B, run time: 1 s, successful read: 1 s ago
^MFinished
I would like to remove every ^M
control character and every ^[[A
sequence to achieve the following desired output;
rescued: 0 B, errsize: 0 B, current rate: 0 B/s
ipos: 0 B, errors: 0, average rate: 0 B/s
opos: 0 B, run time: 1 s, successful read: 1 s ago
Finished
Thus far I've tried:
def main(input=None):
f = open(os.path.abspath(input),'r')
file = f.read()
f.close()
filter(lambda x: x in string.printable, file)
open('output', 'w').write(file)
but doing a cat -v
still shows all the non-standard characters.
Using itertools.ifilter
produces the same result.