<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[实践Ok]Sed 正则替换代码中的日志开关、错误级别值修改、注释代码备案。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Thu, 07 Nov 2013 02:24:34 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：多个项目进行代码的日志打印级别统一替换时，如果文件庞大，数目多，一个个去做显然力不从心，得通过脚本，这种替换sed最适合不过了。<br/><textarea name="code" class="php" rows="15" cols="100">
sed -i &quot;s/my.boosh.com/i.boosh.com/g&quot; *.boosh.conf
</textarea><br/>paste imgid.txt times.txt &#124;awk -F&quot;.&quot; &#039;&#123;print $1&#125;&#039;&#124;awk -F&#039;T&#039; &#039;&#123;print $1&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;$2&#125;&#039;&#124;sed &quot;s/[-:]//g&quot;&#124; paste imgid.txt times.txt &#124;awk -F&quot;.&quot; &#039;&#123;print $1&#125;&#039;&#124;awk -F&#039;T&#039; &#039;&#123;print $1&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;$2&#125;&#039;&#124;sed &quot;s/[-]//g;s/://g&quot;<br/><br/>[28-Jan-2019 20:22:33 Asia/Shanghai] PHP Warning:&nbsp;&nbsp;Redis::connect(): connect() failed: Cannot assign requested address in /root/a.php on line 6<br/>[28-Jan-2019 20:22:33 Asia/Shanghai] PHP Fatal error:&nbsp;&nbsp;Uncaught RedisException: Redis server went away in /root/a.php:7<br/>Stack trace:<br/>CentOS6和7都要打开，模糊替换：<br/><textarea name="code" class="php" rows="15" cols="100">
ansible lottery_api -a&quot;sed -i &#92;&quot;s#tcp_tw_reuse.*#net.ipv4.tcp_tw_reuse = 1#g&#92;&quot; /etc/sysctl.conf&quot;
ansible lottery_api -a&quot;cat /etc/sysctl.conf&#124;grep tcp_tw_reuse&quot;
ansible lottery_api -a&quot;sysctl&nbsp;&nbsp;-p&quot; 
</textarea><br/>linux地址重用 net.ipv4.tcp_tw_reuse:<br/><a href="https://blog.csdn.net/pzqingchong/article/details/53580732" target="_blank">https://blog.csdn.net/pzqingchong/article/details/53580732</a><br/><br/>sed实现去注释，加中间小横：<br/>#BuildRequires: %&#123;_php_fpm&#125;%&#123;php_version&#125;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>#Requires: %&#123;_php_fpm&#125;%&#123;php_version&#125;<br/><br/><textarea name="code" class="php" rows="15" cols="100">
sed -i &quot;s/#BuildRequires/BuildRequires/g&quot; *php55*.spec
sed -i &quot;s/#Requires/Requires/g&quot; *php55*.spec

sed -i &quot;s/#BuildRequires/BuildRequires/g&quot; *php56*.spec
sed -i &quot;s/#Requires/Requires/g&quot; *php56*.spec

sed -i &quot;s/#BuildRequires/BuildRequires/g&quot; *php70*.spec
sed -i &quot;s/#Requires/Requires/g&quot; *php70*.spec
</textarea><br/><br/>fpm&#125;%&#123;php&nbsp;&nbsp;==替换成=&gt; fpm&#125;-%&#123;php：<br/><textarea name="code" class="php" rows="15" cols="100">
sed -i &quot;s/fpm&#125;%&#123;php/fpm&#125;-%&#123;php/g&quot; *php55*.spec
sed -i &quot;s/fpm&#125;%&#123;php/fpm&#125;-%&#123;php/g&quot; *php56*.spec
sed -i &quot;s/fpm&#125;%&#123;php/fpm&#125;-%&#123;php/g&quot; *php70*.spec
</textarea><br/><br/>如题：<br/>I：<br/>我想把：log_threshold =N;<br/>替换为：log_threshold =1;<br/><br/>我想把：show_debug_errors=AnyWord;<br/>替换为：show_debug_errors=false;<br/><br/>II：<br/>error_reporting(E_ALL ^ E_NOTICE); 变：<br/>//error_reporting(E_ALL ^ E_NOTICE);<br/><br/>I)：日志开关，错误级别修改：<br/>一、Sed替换方法如下（该处由scottjiang兄弟提供，后面我发挥了一下下：-））：<br/><textarea name="code" class="php" rows="15" cols="100">
sed &quot;s/log_threshold = .*;$/log_threshold = 1;/g;s/show_debug_errors = .*;$/show_debug_errors = false;/g&quot; index.php &gt; index.php.new
mv&nbsp;&nbsp;index.php.new index.php
</textarea><br/><br/>二、如果不想备份直接替换：<br/><textarea name="code" class="php" rows="15" cols="100">
sed -i&nbsp;&nbsp;&quot;s/log_threshold = .*;$/log_threshold = 1;/g;s/show_debug_errors = .*;$/show_debug_errors = false;/g&quot; index.php
</textarea><br/><br/>三、多个项目的index.php都要统一用sed替换：<br/><textarea name="code" class="php" rows="15" cols="100">
 grep -rl &quot;log_threshold =&quot; ./&#124;grep index.php&#124;xargs sed -i&nbsp;&nbsp;&quot;s/log_threshold = .*;$/log_threshold = 1;/g;s/show_debug_errors = .*;$/show_debug_errors = false;/g&quot; 
</textarea><br/><br/><br/>II)：sed实现对PHP代码某特征给注释一行（如：项目上线时不想让其打开错误报告给用户）：<br/>如想：<br/>error_reporting(E_ALL ^ E_NOTICE); 变：<br/>//error_reporting(E_ALL ^ E_NOTICE);<br/>sed替换方法:<br/><textarea name="code" class="php" rows="15" cols="100">
sed &#039;s/error_reporting/&#92;/&#92;/error_reporting/g&#039;&nbsp;&nbsp;./index.php
</textarea><br/>而：也可结合上面三实现批量替换实现多个文件包含上面串的该行给予注释掉:<br/><textarea name="code" class="php" rows="15" cols="100">
grep -rl &quot;error_reporting(E_ALL ^ E_NOTICE);&quot; ./&#124;grep index.php&#124;xargs sed -i &#039;s/error_reporting/&#92;/&#92;/error_reporting/g&#039; 
</textarea><br/><br/>四、替换由mysqldump出的自境长字段为0: <br/>情形：Mysqldump出的线下自增长字段，会有默认值，而放到外网则需要从线上开始，此SQL也需要替换的（http://jackxiang.com/post/1188/）<br/>deo` VALUES (1121,NULL,&#039;<br/>用sed替换：<br/>sed -i &quot;s/([0-9]*/(0/g&quot; /tmp/result.sql&nbsp;&nbsp;<br/>替换后，为0，上线插入时则从线上默认增长，而不是上面的1121：<br/>_video` VALUES (0,NULL,&#039;2&#039;<br/><br/>sed -i &#039;s/([0-9]*,/(0,/g&#039;&nbsp;&nbsp; //文件名替换(12122, ==&gt;(0,
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践Ok]Sed 正则替换代码中的日志开关、错误级别值修改、注释代码备案。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>