<?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>Marius van Witzenburg &#187; Replace</title>
	<atom:link href="http://mariusvw.com/tag/replace/feed/" rel="self" type="application/rss+xml" />
	<link>http://mariusvw.com</link>
	<description>We fight for our survival, we fight!</description>
	<lastBuildDate>Tue, 27 Dec 2011 10:35:27 +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>Some useful information about PHP RegEx</title>
		<link>http://mariusvw.com/2011/07/02/some-useful-information-about-php-regex/</link>
		<comments>http://mariusvw.com/2011/07/02/some-useful-information-about-php-regex/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 10:04:57 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[Grep]]></category>
		<category><![CDATA[Match]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Preg]]></category>
		<category><![CDATA[RegEx]]></category>
		<category><![CDATA[Replace]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=5961</guid>
		<description><![CDATA[This information can be handy with the following PHP functions: * preg_filter * preg_grep * preg_last_error * preg_match_all * preg_match * preg_quote * preg_replace_callback * preg_replace * preg_split What is a regex? At its most basic level, a regex can be considered a method of pattern matching or matching patterns within a string. In PHP [...]]]></description>
			<content:encoded><![CDATA[<p>This information can be handy with the following PHP functions:<br />
  * preg_filter<br />
  * preg_grep<br />
  * preg_last_error<br />
  * preg_match_all<br />
  * preg_match<br />
  * preg_quote<br />
  * preg_replace_callback<br />
  * preg_replace<br />
  * preg_split</p>
<h2>What is a regex?</h2>
<p>At its most basic level, a regex can be considered a method of pattern matching or matching patterns within a string. In PHP the most oft used is PCRE or "Perl Compatible Regular Expressions". Here we will try to decypher the meaningless hieroglyphics and set you on your way to a powerful tool for use in your applications. Do not try to understand all this in a single sitting. Instead, take in a little and come back as you grasp various concepts.</p>
<h2>Where do I begin?</h2>
<p>At the beginning.</p>
<p>Lets create a string.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// echo our string</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If we simply wanted to see if the pattern 'abc' was within our larger string we could easily do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/abc/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The code above will echo '1'. This is because it has found 1 match for the regex. That means it has found the pattern 'abc' once in the larger string. [[http://www.php.net/preg-match|preg_match()]] will count zero if there is no matches, or one if it finds a match. This function will stop searching after the first match. Of course, you would not do this in a real world situation as php has functions for this such as [[http://www.php.net/strpos|strpos()]] and [[http://www.php.net/strstr|strstr()]] which will do this much faster.</p>
<h2>Match beginning of a string</h2>
<p>Now we wish to see if the string begins with abc. The regex character for beginning is the caret ^. To see if our string begins with abc, we use it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match the beginning of the string</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^abc/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if it matches we echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string begins with abc'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if no match is found echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>From the code above we see that it echo's the line ''The string begins with abc''. The forward slashes are a delimeter that hold our regex pattern. The quotations are used to 'wrap it all up'. So we see that using the caret(^) will give us the beginning of the string, but NOT whatever is after it.</p>
<h2>What if I want case insensitive?</h2>
<p>If you used the above code to find the pattern ABC like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^ABC/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>the script would have returned the message:</p>
<p>No match found</p>
<p>This is because the search is case sensitive. The pattern 'abc' is not the same as 'ABC'. To match both 'abc' and 'ABC' we need to use a modifier to make the search case in-sensitive. With php regex, like most regex, is use 'i' for insensitive. So now our script might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match our pattern</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^ABC/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// echo this is it matches</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string begins with abc'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if not match is found echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now the script will find the pattern abc. It would also match any case in-sensitive combination of abc, ABC, Abc, aBc, and so on.</p>
<p>More on [[http://php.net/manual/en/reference.pcre.pattern.modifiers.php|modifiers]] later.</p>
<h2>How do I find a pattern at the end of a string?</h2>
<p>This is done in much the same way as with finding a a pattern at the beginning of a string. A common mistake made by many is to use the $ character to match the end of a string. This is incorrect and \z should be used. Consider this..</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^foo$/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;foo<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>This will return true as $ is like \Z which is like (?=\z|\n\z). So when a newline is not wanted, $ should not be used. Also $ will match multiple times with the /m modifier whereas \z will not. Lets make a small change to the code from above by removing the caret(^) at the beginning of the pattern and putting \z at the end of the pattern, we will keep the case in-sensitive modifier in to match any case.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match our pattern at the end of the string</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/89\z/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if our pattern matches we echo this </span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string ends with 89'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if no match is found we echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The script now will show the line<br />
''The string ends with 89''<br />
because we have matched the end of the string with the pattern 89. Pretty easy stuff so far.</p>
<h2>Meta characters</h2>
<p>During our first look at regex we did some simple pattern matching. We also introduced the caret(^) and the dollar($). These characters have special meaning. As we saw, the caret(^) matched the beginning of a string and the dollar matched the end of a string. These characters, along with others are called Meta characters. Here is a list of the Meta characters used for regex:<br />
  * . (Full stop)<br />
  * ^ (Carat)<br />
  * * (Asterix)<br />
  * + (Plus)<br />
  * ? (Question Mark)<br />
  * { (Opening curly brace)<br />
  * [ (Opening brace)<br />
  * ] (Closing brace)<br />
  * \ (Backslash)<br />
  * | (Pipe)<br />
  * ( (Opening parens)<br />
  * ) (Closing parens)<br />
  * } (Closing curly brace)<br />
We will look at each of these during this tutorial, but it is important that you know what they are. If you wish to search a string that contains one of these characters, eg: "1+1" then you need to escape the the meta character with a backslash like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1+1=2'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// try to match our pattern</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^1\+1/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if the pattern matches we echo this</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The string begins with 1+1'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// if no match is found we echo this line</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'No match found'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>From the code above you will see the script print:<br />
''The string begins with 1+1''<br />
because it found the pattern 1+1 and ignored or escaped the special meaning of the + symbol. If you were to not escape the meta character and use the regex</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^1+1/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>you would not find a match.<br />
If you are looking for a backslash, you need to escape that also. But, we also need to escape the control character too, which is itself a backslash, hence we need to escape twice like this</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">\\\\</pre></div></div>

<h2>What do the other Meta characters do?</h2>
<p>We have already seen the caret **^** and the dollar **$** in action, so now lets look at the others, beginning with the square braces [ ]. These Meta characters are used for specifying a character class.</p>
<p>A what?</p>
<p>A Character Class. This is just a set of characters you wish to match. They can be listed individually like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[abcdef]</pre></div></div>

<p>or as a range seperated by a **-** symbol like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[a-f]</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// create a string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'big'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Search for a match</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/b[aoiu]g/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Source: <a href="http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html">http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/07/02/some-useful-information-about-php-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to replace content in columns with a simple MySQL query</title>
		<link>http://mariusvw.com/2011/06/14/how-to-replace-content-in-columns-with-a-simple-mysql-query/</link>
		<comments>http://mariusvw.com/2011/06/14/how-to-replace-content-in-columns-with-a-simple-mysql-query/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 11:47:48 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[Replace]]></category>
		<category><![CDATA[Search]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=237</guid>
		<description><![CDATA[Actually searching and replacing content in MySQL is quite simple, you just have to know the REPLACE function of MySQL Here you have a simple example how to do the trick: UPDATE `table` SET `field` = REPLACE&#40;`field`, 'search_for', 'replace_with'&#41;; Simple huh?]]></description>
			<content:encoded><![CDATA[<p>Actually searching and replacing content in <a href="http://mysql.com/">MySQL</a> is quite simple, you just have to know the <a href="http://dev.mysql.com/doc/refman/5.1/en/replace.html">REPLACE</a> function of MySQL <img src='http://mariusvw.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Here you have a simple example how to do the trick:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #008000;">`table`</span> <span style="color: #990099; font-weight: bold;">SET</span> <span style="color: #008000;">`field`</span> <span style="color: #CC0099;">=</span> <span style="color: #000099;">REPLACE</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`field`</span><span style="color: #000033;">,</span> <span style="color: #008000;">'search<span style="color: #008080; font-weight: bold;">_</span>for'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'replace<span style="color: #008080; font-weight: bold;">_</span>with'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>Simple huh? <img src='http://mariusvw.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/06/14/how-to-replace-content-in-columns-with-a-simple-mysql-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to fix inconsistent line ending (EOL) style with find and Perl</title>
		<link>http://mariusvw.com/2010/08/25/how-to-fix-inconsistent-line-ending-eol-style-with-find-and-perl/</link>
		<comments>http://mariusvw.com/2010/08/25/how-to-fix-inconsistent-line-ending-eol-style-with-find-and-perl/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 09:56:24 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[CFM]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Ending]]></category>
		<category><![CDATA[EOL]]></category>
		<category><![CDATA[Find]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Inconsistent]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Line]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PL]]></category>
		<category><![CDATA[Replace]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[TXT]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=4967</guid>
		<description><![CDATA[If you work with subversion you might get this error when you got files that have been edited on different operating systems like Windows, Linux, FreeBSD or Mac OS X. Well, the fix is quite simple. You simply replace the wrong line endings with right ones depending of which you want. In my situation I [...]]]></description>
			<content:encoded><![CDATA[<p>If you work with subversion you might get this error when you got files that have been edited on different operating systems like Windows, Linux, FreeBSD or Mac OS X.</p>
<p>Well, the fix is quite simple. You simply replace the wrong line endings with right ones depending of which you want. In my situation I want unix style line endings.</p>
<p>Replace in PHP/JavaScript files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/rn/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/r/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/rn/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/r/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;</pre></div></div>

<p>In case you want to replace them in multiple file types you can adjust the command. In this example we want to replace in the following file types:</p>
<ol>
<li>asp</li>
<li>cfm</li>
<li>css</li>
<li>html</li>
<li>js</li>
<li>php</li>
<li>pl</li>
<li>txt</li>
</ol>
<p>Use the following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.asp'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.cfm'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.css'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.html'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.pl'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.txt'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/rn/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;
<span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.asp'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.cfm'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.css'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.html'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.js'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.php'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.pl'</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.txt'</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-wpe</span> <span style="color: #ff0000;">'s/r/n/g'</span> <span style="color: #ff0000;">'{}'</span> ;</pre></div></div>

<p>Keep in mind, you may use these commands on your own risk. I'm not responsible if you lose your work <img src='http://mariusvw.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Now you should be able to commit your files again <img src='http://mariusvw.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2010/08/25/how-to-fix-inconsistent-line-ending-eol-style-with-find-and-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

