Use shell to search for and replace multiple files

Source: Internet
Author: User

// Use shell to search for multiple files <br/> find. -type f | xargs grep flash <br/> description: <br/> find the files in the front directory and Its subdirectories that contain flash files <br/> // <br/> record the xargs command: <br/> 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. <br/> how to view ARG_MAX values: <br/> getconf ARG_MAX <br/> // <br/> Search for multiple files and replace them with commands. <br/> grep flash $ (find. -type f) <br/> Note: <br/> $ () is used to replace commands, and shell commands are used in parentheses; shell executes the command in parentheses and returns the entire $ (...) replace with the output of the command <br/> there are two types of command replacement: $ (), and two reverse quotation marks pair find. -type f Branch

 

 

// Replace-sed in multiple files <br/> to ensure that the unreplaced file is not replaced, find out which will be replaced in the file <br/> find-type f! -Path '*. svn * '| xargs sed-n'/Ookong inc/P' <br/> Note: <br/> 1. find is filtered out first. svn directory and Its subdirectories <br/> 2. xargs sends parameters to the sed command <br/> 3. sed performs search, print only the rows that meet the requirements <br/> // replace <br/> find-type f! -Path '*. svn * '| xargs sed-I's/Ookong inc/Ookong Ltd. co. /G' <br/> Note: <br/> 1. The sed I option is directly replaced in the file, instead of printing the replacement result. <br/> 2, g. replace all the matches in each line. <br/> // <br/> In addition, a perl multi-file search program: ack <br/> -- display the row number and file

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.