0

I am working with Python on a Linux server. I have some output which I am storing in a text file. The output file contains some control characters like ^H and ^M which I am not able to replace with. I want these characters to be replace with null string. The control characters are also there in new lines. It would be very thankful if someone could just guide me. Thank you!

user3379410
  • 176
  • 1
  • 11
  • 1
    possible duplicate of [How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?](http://stackoverflow.com/questions/811193/how-to-convert-the-m-linebreak-to-normal-linebreak-in-a-file-opened-in-vim) – uralbash Feb 19 '15 at 10:37
  • Have you tried anything so far? By showing your attempts and describing what parts you are having difficulty with, we get a better understanding of your proficiency and can give a more precise answer. Do you need a Python implementaion, or can this be done in Vim as well (because you added that tag)?! – Ingo Karkat Feb 19 '15 at 12:14
  • You tagged this question with 'vim' - you can easily delete a control character in vim with 'x' just as you can remove any character. – David Ljung Madison Stellar Feb 19 '15 at 16:55

1 Answers1

1

You could read the string in and convert to charArray. Once you do this you can look at each character by its decimal value, then use a simple if/or statement to change contol characters (by their ascii decimal values) into what ever you like including null.

I did something like this is java but for Capital letters. here Python should be a little simpler.

Community
  • 1
  • 1
rawm
  • 36
  • 4