I have a text file I have FTP'd to UNIX so that I can use it to load into our Baan system. When vi the file, I can see that there are formatting characters at the end of each line (^M). To get rid of these, I have read that the following should work:
:%s/^M$//g - with the ^M being the equivalent of CTRL V CTRL M
Unforutnately, when trying to type this command I can only get to the "CTRL M" before I get the error message "Substitute pattern match failed." Does anyone know why I cannot type the whole command shown above or is there something that cause the command to execute before the entire command is typed?
Thanks Gurus! I never heard of or used DOS2UNIX so maybe I will try it sometime. I did take a look at my FTP settings and it was set on "Automatic." After changing it to "ASCII," I FTPd some files over that I had problems with in the past. Sure enough, no more problems with character formatting! I guess I assumed that "Automatic" would always give me the best method of moving the file.
I still would also be interested in knowing why I am not able to use the command %s/^M//g. The commands I am using to get the formatting character are ctrl v followed immediately by ctrl m. There is no use of the shift key, minus signs, plus signs, etc - only the ctrl button with the letter v follwed by the ctrl button and the letter m.
Nagarajan,
Your process is lengthy. I simply go for following
echo "foo" >> file-name
Then edit file using "vi" editor. your "^M" will be visible. Just remove that using compatible "vi" pattern-replacement method. Remember last-line "foo" and save file.
Special attention is required in above make sure you use ">>" and NOT ">" otherwise its gone.
hey i never tried this in vi but works for vim
just ^M character is carriage return ( which indicates file is in DOS format ) so just open file and do
:set fileformat=unix after that save file .