Linux tips-search and replace multiple files

Source: Internet
Author: User

Search

// Search for multiple files using shell
Find.-Type F | xargs grep flash
Note:
Find the files in the previous directory and Its subdirectories that contain Flash files.
//
Record the xargs command:
Xargs obtains the parameter list and one row in the standard input, and then sends them to another command in a large group (determined by the arg_max value of the host, this command is used as the xargs parameter.
How to view arg_max values:
Getconf arg_max
//
//
Search for multiple files and replace them with commands.
Grep flash $ (find.-Type F)
Note:
$ () Is a command replacement, with shell commands in parentheses. Shell executes the commands in parentheses and replaces $ (...) with the command output.

There are two methods to replace a command: $ () and two reverse quotation marks pair find.-Type F pair.

 

Replace

// Replace-sed in multiple files
To ensure that the replacement should not be replaced, first find out in the file which will be replaced
Find-type F! -Path '*. SVN *' | xargs sed-n'/ookong INC/P'
Note:
1. Find first filters out the. SVN directory and Its subdirectories.
2. xargs sends parameters to the SED command
3. Sed performs a search and only prints the rows that meet the requirements.
//
// Replace
Find-type F! -Path '*. SVN *' | xargs sed-I's/ookong INC/ookong Ltd. co./G'
Note:
1. Sed's I option is directly replaced in the file, instead of printing the replacement result.
2.g replace all the matches in each line.
//
//
In addition, a Perl multi-file search Program : ACK
-- Display the row number and file

Vim find replacement (see http://www.cnblogs.com/mo-beifeng/archive/2011/10/02/2198303.html)

 

Other Replacement Methods:

One is the mahuinan method, the other is the sumly method, and the other is the 30 t method as follows: 

 

 

 

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.