The FreeBSD Diary
Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link.
Stripping ^M from your files 4 March 2000
If you have transferred a file from MS Windows to FreeBSD, you might find
the file looks like this:
<html>^M ^M <head>^M <title>The FreeBSD Diary -- Article Maintenance</title>^M <meta name="description" content="BLANK">^M <meta name="keywords" content="FreeBSD">^M
That "^M" is control-M, which is a carriage return, and is not needed in Unix file systems. To remove this extra character, run the following script:
perl -pi -e "s:^V^M::g" <filenames>
where ^V is actually control-V and ^M is actually control-M (you must type these yourself, don't just copy and paste this command). Control-V will not be displayed on your screen.
<filenames> is the list of files to be converted.
NOTE: I'm told that if you use ASCII mode to transfer your files, this problem won't occur.
|I like people writing in with options. Here are two other ways to
get rid of the ^M characters:
cat <filename1> | tr -d "^V^M" > <newfile>
sed -e "s/^V^M//" <filename> > <output filename>