Use Find and SED
# First query the number (sed-N)
Find.-Name '*. htm' | xargs sed-n'/old/P'
# Replace (sed-I)
Find.-Name '*. htm' | xargs sed-I's/old/new/G'
Use grep and SED
Grep-l old *. htm | xargs sed-n "/old/P"
Sed-n'/old/P' grep-l old *. htm'
Use Find and Perl
Find.-Name '*. htm' | xargs Perl-pi-E's | old | new | G'
Refer:
Http://hi.baidu.com/msingle/blog/item/3b125b3fc0e1efe255e72375.html
Http://blog.csdn.net/zhangboyj/article/details/6215429
// Use shell to search for multiple files
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-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