#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2015
    Posts
    6
    Rep Power
    0

    Removing ^M from file via Vi (Problem)


    Hi all

    I am trying to remove the character '^M' from a text file I have - I've tried using :%/^M//g and other combinations, to which Vi responds E486: pattern not found: ^M.

    Here is a screen shot of the response and evident ^M's in my file.



    Any help would be appreciated!

    Thanks
  2. #2
  3. Nosey Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,607
    Rep Power
    9417
    See how the ^Ms are colored unlike everything else? vim is telling you that those aren't literally the characters "caret + capital 'M'" but a control character: ASCII 13 (thus the M). Which is a \r.

    It may be reading the file using Unix line endings. Which there don't seem to be any of. What happens if you use the command ":e ++ff=mac"?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2015
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    See how the ^Ms are colored unlike everything else? vim is telling you that those aren't literally the characters "caret + capital 'M'" but a control character: ASCII 13 (thus the M). Which is a \r.

    It may be reading the file using Unix line endings. Which there don't seem to be any of. What happens if you use the command ":e ++ff=mac"?
    When I use ":e ++ff=mac" I get this occur:



    However when i do :wq to save it, then reopen the file I get the original format of the document with the ^M in it. It doesn't save as a file with the correct formatting like shown in the picture above (ff=mac applied).

  6. #4
  7. Nosey Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,607
    Rep Power
    9417
    That command just reloads the file with a different line endings format applied. Doesn't actually change the file.

    Your vim seems to be attempting a set of line endings that doesn't include "mac", which is typically what happens for a vim running on Linux or Windows.
    Take a look here to find out what's going on, and how to convert the file.

IMN logo majestic logo threadwatch logo seochat tools logo