<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech Stuff &#187; vi</title>
	<atom:link href="http://tech-stuff.org/tag/vi/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech-stuff.org</link>
	<description>Hosting Tips &#38; Tricks</description>
	<lastBuildDate>Fri, 20 May 2011 14:08:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Use the vi editor binary mode to remove control-m characters</title>
		<link>http://tech-stuff.org/use-the-vi-editor-binary-mode-to-remove-control-m-characters/</link>
		<comments>http://tech-stuff.org/use-the-vi-editor-binary-mode-to-remove-control-m-characters/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 17:48:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[hosting]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[control-m]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://tech-stuff.org/?p=120</guid>
		<description><![CDATA[If you&#8217;ve ever opened a text file with vi (or vim) and saw a message on the bottom of the screen that says &#8220;dos&#8221; or &#8220;dos format&#8221;, there&#8217;s a reason for this. The file was probably created on a DOS or Windows computer, and it contains extra binary characters that are not normally found in [...]]]></description>
			<content:encoded><![CDATA[<p><span>If you&#8217;ve ever opened a text file with vi (or vim) and saw a message on the bottom of the screen that says &#8220;dos&#8221; or &#8220;dos format&#8221;, there&#8217;s a reason for this. The file was probably created on a DOS or Windows computer, and it contains extra binary characters that are not normally found in a file created on a Unix or Linux system.</span></p>
<p>You can see this very easily by closing your current vi session, and then re-opening the file with vi, but also using the <code>-b</code> command line argument, like this:</p>
<pre>vi -b myfile.txt</pre>
<p>The <code>-b</code> indicates that you want to open the file in <em>binary</em> mode, and in this mode you can see a bunch of mysterious <code>^M</code> characters at the end of each line. These are the extra characters that tell your Unix system that the file was created on a DOS system.</p>
<p>These extra characters are <em>usually</em> harmless, but some times they can lead to error messages, the most common error message being &#8220;bad interpreter.&#8221; You get the &#8220;bad interpreter&#8221; error message when there is a <code>^M</code> character at the end of the first line of a script, like the first line of this Perl script:</p>
<pre>#!/usr/bin/perl^M
#
# more code down here ...
#</pre>
<p>The way to get rid of that &#8220;bad interpreter&#8221; error message is to get rid of that <code>^M</code> character, which I&#8217;ll discuss next.</p>
<h2>Removing those ^M characters</h2>
<p>Getting rid of these pesky <code>^M</code> characters is pretty easy. First, open the file with the <code>-b</code> option, as shown earlier:</p>
<pre>vi -b myfile.txt</pre>
<p>Next, type the &#8220;:&#8221; character, to put the vi editor in last-line mode.</p>
<p>Now enter the following command, but where you see the <code>^M</code> character in that line, what you really need to type is this character sequence: <code>[Ctrl]v [Ctrl]m</code></p>
<p>(That&#8217;s &#8220;control v, control m&#8221;.)</p>
<p>Here&#8217;s the sequence to type:</p>
<pre>1,$s/^M//</pre>
<p>Follow that with an [Enter] keystroke.</p>
<p>What this command means is, &#8220;From the first line of the file to the last line of the file, replace all <code>^M</code> characters with nothing.&#8221;</p>
<p>If everything worked successfully you&#8217;ll see that all of those <code>^M</code> characters are now gone.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech-stuff.org/use-the-vi-editor-binary-mode-to-remove-control-m-characters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/22 queries in 0.013 seconds using disk: basic
Object Caching 208/222 objects using disk: basic

Served from: tech-stuff.org @ 2012-02-05 22:47:14 -->
