[techtalk] vi technique for dos2unix
Andrew Plumb
andrew at plumb.org
Wed May 3 10:46:17 EST 2000
On Tue, 2 May 2000, Robert Kiesling wrote:
> Usually when translating files from msdos to unix, you have to
> translate at least the line termination characters. Msdos
> uses a carraige return-line feed combination (hex 0xd0xa) to
> terminate lines, while unices use only a line feed. Some utilities
> perform the translation automatically. In any event, you can
> do the same with a utility like "tr," I believe there's an
> example of how to do this conversion in the man pages.
The Quick'n'dirty way to do this in vi is as follows:
1. Open the dos text file in vi.
vi dosfile.txt
2. Type the following:
:%s/^M//g
...where you "compose" the ^M character by pressing Ctrl+v then Ctrl+m
3. Save the file:
:w New.Unix.File.txt
The above :%s/^M//g means "replace (substitute) every ^M character with no
character". More generally, you can do :%s/old/new/g to replace every
instance of "old" with "new"; it's the final "g" after the last slash
makes it replace every instance, not just the first instance.
Note: This will replace any instance of the sequence of letters "old"; it
will replace the "old" in sold with "new" to form snew, and gold will
become gnew. :-)
Hope this helps!
Andrew.
--
Andrew Plumb, VE3SLG
mailto://andrew(at)plumb(dot)org
http://www.plumb.org/tekmage/
spk2_0.0.2: http://www.plumb.org/tekmage/source/spk2/
More information about the Techtalk
mailing list