Replace specified strings in files in batches in Centos

Source: Internet
Author: User
Tags centos perl script


These two Angels used the locomotive to collect some data because they generated a lot of SQL files. I want to replace the fixed content in each SQL file with another content.

Manual file configuration change is a bit impractical, so google, find a good way to replace file content in batches.

The command structure is as follows:

Find-name 'file name to be searched' | xargs perl-pi-e's | replaced string | G'

In the following example, replace "love margin" with "www.111cn.net" in the current directory and all SQL files in all subdirectories"
Find-name *. SQL | xargs perl-pi-e's | xiangxiangyuan | www.111cn.net | G'


The Perl language is used here,

Perl-pi-e

Add the-e option to the Perl command, followed by a line of code, and then it will run the code like running a common Perl script.

Using Perl from the command line can help implement some powerful and real-time conversions. Studying regular expressions carefully and using them correctly will save you a lot of manual editing work.

Change the content of all conf files under/usr/local/apache/conf to/data/wwwroot ]. The procedure is as follows:

# Sed-I "s/\/usr \/local \/apache \/htdocs/\/data \/wwwroot/g" 'find. -name "*. conf "| xargs grep"/usr/local/apache/htdocs "-rl'
Or

# Find.-type f-exec sed-I's #/usr/local/apache/htdocs #/data/wwwroot # G '{}\;

Related Article

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.