in reply to Re: ^M gets added to the end of the line while replacing strings
in thread ^M gets added to the end of the line while replacing strings

I am working on a RED-HAT 7.3 and the file originated on a windows 2000 system. But before I executed the command I opened the file on a vi editor and did not see any ^M characters. Also I just now tried to create a new file using vi editor and then tried the same command. Now I did not see any ^M characters. So you are right, the one-liner is fine. So maybe it has got something to do with the file being originated in wondows. Thanks for your help.
  • Comment on Re: Re: ^M gets added to the end of the line while replacing strings

Replies are listed 'Best First'.
Re: Re: Re: ^M gets added to the end of the line while replacing strings
by sauoq (Abbot) on Jul 08, 2003 at 00:33 UTC
    So maybe it has got something to do with the file being originated in wondows.

    Yes, it has everything to do with that.

    The dos2unix utility is your friend.

    You can fix it with perl too using a command like like:

    perl -i.bak -pe 's/\r\n/\n/' file.txt

    BTW, vi tries to be smart about whether it displays those ^M characters... which is probably why you didn't see them the first go around.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Re: ^M gets added to the end of the line while replacing strings
by bobn (Chaplain) on Jul 08, 2003 at 01:11 UTC

    'vi' on linux is actually vim, and it "helps" by dealing with ^M characters transparently.

    To have vim show them with the ^M display you're used to, use vim -C name_of_win_file.

    --Bob Niederman, http://bob-n.com