snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#114908

Bash

replace X with Y in all files in a project using sed

sed -i '' -e 's/X/Y/g' $(find . -type f)
https://snipt.net/embed/c195316a2cdd5d8900d146a160c0aba7/
https://snipt.net/raw/c195316a2cdd5d8900d146a160c0aba7/
c195316a2cdd5d8900d146a160c0aba7
bash
Bash
1
2014-04-16T18:22:22
True
False
Feb 18, 2014 at 04:52 PM
/api/public/snipt/114908/
replace-x-with-y-in-all-files-in-a-project-using-sed
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>sed -i <span class="s1">&#39;&#39;</span> -e <span class="s1">&#39;s/X/Y/g&#39;</span> <span class="k">$(</span>find . -type f<span class="k">)</span> </span></pre></div> </td></tr></table>
replace, sed
#77238

PHP

check keyword in string : strpos()

1
2
3
4
5
6
<?php
// © 2012-2013, [ Abstract Codify ] Abstractcodify.com All Rights Reserved.
if ( strpos( $all_string , 'keyword' ) !== false ) 
{
	echo 'true ';
}
https://snipt.net/embed/7d2d9604d04d99c86a277981437e7546/
https://snipt.net/raw/7d2d9604d04d99c86a277981437e7546/
7d2d9604d04d99c86a277981437e7546
php
PHP
6
2014-04-12T11:20:50
True
True
Aug 27, 2013 at 12:06 AM
/api/public/snipt/77238/
check-keyword-in-string-strpos
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// © 2012-2013, [ Abstract Codify ] Abstractcodify.com All Rights Reserved.</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span> <span class="p">(</span> <span class="nb">strpos</span><span class="p">(</span> <span class="nv">$all_string</span> <span class="p">,</span> <span class="s1">&#39;keyword&#39;</span> <span class="p">)</span> <span class="o">!==</span> <span class="k">false</span> <span class="p">)</span> </span><span id="L-4"><a name="L-4"></a><span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="s1">&#39;true &#39;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
change, replace, string
#63821

MySQL

find/replace MySQL

update table set field = REPLACE(field, 'string', 'anothervalue') WHERE field LIKE '%string%';
https://snipt.net/embed/174004aca4c229297e85a91df9066abb/
https://snipt.net/raw/174004aca4c229297e85a91df9066abb/
174004aca4c229297e85a91df9066abb
mysql
MySQL
2
2014-04-17T19:58:02
True
False
Jun 11, 2013 at 08:36 AM
/api/public/snipt/63821/
findreplace-mysql
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">update</span> <span class="k">table</span> <span class="kt">set</span> <span class="n">field</span> <span class="o">=</span> <span class="k">REPLACE</span><span class="p">(</span><span class="n">field</span><span class="p">,</span> <span class="s1">&#39;string&#39;</span><span class="p">,</span> <span class="s1">&#39;anothervalue&#39;</span><span class="p">)</span> <span class="k">WHERE</span> <span class="n">field</span> <span class="k">LIKE</span> <span class="s1">&#39;%string%&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
find, mysql, replace