Replacing File Content in batches in Linux

Source: Internet
Author: User
Tags perl script

Maven is used to build an application in the past two days. Due to the large project, there are more than 700 pom S. xml file, even more depressing is in many pom. the url of the resource library is specified separately in the xml file. I need to uniformly specify the URLs of these resource libraries to the local central nexus library.

Manually changing the file configuration is a bit impractical, So google, find a good way to replace the 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, the "example.

Find-name 'pom. xml' | xargs perl-pi-e's | http://repo1.maven.org/maven2 | http: // localhost: 8081/nexus/content/groups/public | 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.

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.