Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Jan 1999 23:49:42 -0800
From:      Ludwig Pummer <ludwigp@bigfoot.com>
To:        "Robert Luce" <rwl@gymnet.com>, "charon@freethought.org" <charon@freethought.org>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@FreeBSD.ORG>
Subject:   Re: replacing ^M in vi
Message-ID:  <4.1.19990110234101.00a91500@mail-r>
In-Reply-To: <199901110711.XAA18400@hub.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Just some further info...
if you were to do a hex dump ("hd") of the text file, you would see at the
end of each line an "0d 0a", that's an ASCII 13 followed by an ASCII 10,
aka CRLF.

BTW, two simple perl scripts which were posted on this list a long time ago
(sometime before Oct. 5, 1997) take care of CRLF conversions for you:

---unix2dos---
#!/usr/bin/perl -pi
#
# Convert Unix text file to DOS file format.  Conversion is done in-place.
#
# Usage: unix2dos unixfile ...

print STDERR "Converting \"$ARGV\" ...\n" if (eof || ($. == 0));
s/$/\015/;                      # tack on ^M
s/\n/\n\032/ if (eof);          # DOS ^Z at end of file.

---dos2unix---
#!/usr/bin/perl -pi
#
# Convert DOS text file to Unix file format.  Conversion is done in-place.
#
# Usage: dos2unix dosfile ...

print STDERR "Converting \"$ARGV\" ...\n" if (eof || ($. == 0));
s/\015$//;                      # strip ^M from end of line.
s/\032$//;                      # strip ^Z if we see it (which'll be at EOF).

At 11:10 PM 1/10/99 , Robert Luce wrote:
>%s/<ctrl-v><enter>//g
>
><ctrl-v> means press control-v
><enter> means hit the enter key or press control-m
>
>On Sun, 10 Jan 1999 22:59:10 -0800, charon@freethought.org wrote:
>
>>Whenever I save a plain text file in WinNT and open it in FreeBSD, at the
>>end of every line is a "^M".  How do I get rid of these?  I tried writing a
>>little C++ program to copy all text except "^M" to another file, but it
>>doesn't work because C++ treats the ^ and the M as different characters,
>>whereas vi treats them as _one_ character.  After searching the mailing
>>list archives, I came up with the syntax ":%s/stuff/other stuff/g" as the
>>oh-so-intuitive replace command in vi, and I tried it, but to no avail (it
>>says "no match found").  Any suggestions?  Thanks,

--Ludwig Pummer ( ludwigp@bigfoot.com )
ICQ UIN: 692441 (  ludwigp@email.com  )

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4.1.19990110234101.00a91500>