Sed in linux the log switch, error level value modification, annotation code in the code

Source: Internet
Author: User

Background: Multiple items in the code of the log printing level unified replacement, if the file size, the number of many, to do it obviously powerless, through the script, this replacement sed the most suitable.
Title:
I:
I want to put: Log_threshold =n;
To be replaced by: Log_threshold = 1;

I want to put: Show_debug_errors=anyword;
To be replaced by: Show_debug_errors=false;

Ii:
Error_reporting (e_all ^ e_notice);

Change:

Error_reporting (e_all ^ e_notice);

I): Log switch, error level modification:

First, the SED replacement method is as follows (this place is provided by the Scottjiang brothers, I played a little later:-)):

Sed "s/log_threshold =. *;$/log_threshold = 1;/g;s/show_debug_errors =. *;$/show_debug_errors = false;/g" index.php > I Ndex.php.new
MV Index.php.new index.php


Second, if you do not want to back up the direct replacement:


Sed-i "S/log_threshold =. *;$/log_threshold = 1;/g;s/show_debug_errors =. *;$/show_debug_errors = false;/g" index.php


The index.php of multiple projects should be unified with SED replacement:


Grep-rl "Log_threshold ="/|grep Index.php|xargs sed-i "s/log_threshold =. *;$/log_threshold = 1;/g;s/show_debug_error s =. *;$/show_debug_errors = false;/g "

II): SED implementation of the PHP code to a feature to comment on a line (such as: The project online do not want it to open error reporting to users):
If you want to:
Error_reporting (e_all ^ e_notice); Change:
Error_reporting (e_all ^ e_notice);
Sed substitution method:


Sed ' s/error_reporting///error_reporting/g './index.php

And: can also be combined with the above three implementation of bulk replacement to achieve multiple files containing the above string of the line to give comments off:


Grep-rl "error_reporting (e_all ^ e_notice);/|grep Index.php|xargs ' sed-i '


To replace the mysqldump from the long field from the border of 0:

Case: Mysqldump out of the line from the growth field, there will be a default value, and the extranet will need to start from the line, this SQL also needs to be replaced (http://www.111cn.net/)
Deo ' VALUES (1121,null, '
Replace with SED:
Sed-i "s/([0-9]*/0/g"/tmp/result.sql
After the replacement, for 0, when the line is inserted, the default growth from the online, rather than the above 1121:
_video ' VALUES (0,null, ' 2 '

Sed-i ' s/([0-9]*,/0,/g '   //filename substitution (12122, ==> (0,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.