linux:列出包含多个单词的文件

时间:2017-01-27 14:45:30

标签: linux grep

我试图找到一种方法来列出目录树中的所有文件(递归地),其中包含多个单词。

在搜索时,我找到了<cfset structure1 ={ name = ["john","mary","sue","joe","bob"], prodID = ["94","62","24","48","64"], skuID = ["020402","024040","101010","780080","232332"], distCost = ["34.99","44.99","54.99","64.99","19,99"], retailCost = ["50","60","70","90","30"], bv = ["4","5","6","7","8"], cnt = [#arrayLen(name)#]} /> 但是|等示例诱导OR。我想和... ...

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

GNU grepGNU xargs一起使用,

grep -ERl 'toto' | xargs -r grep 'tata'

第一个grep列出包含模式toto的文件,然后将其提供给xargs,并使用第二个grep列出包含tata的文件。 -r标记用于确保第二个grep不会在空输出上运行。

-r页面xargs中的man标记,

-r, --no-run-if-empty
       If the standard input does not contain any nonblanks, do not run the command.  
       Normally, the command is run once even if there is  no  input. This option is a GNU 
       extension.

答案 1 :(得分:1)

$service = new Google_Service_Directory($client); $password = crypt ( "Password", $salt="IamSecretkey" ); $userObj = new Google_Service_Directory_User( array( 'password' => $password ) ); try{ $results = $service->users->update("danish@XXXX.in", $userObj ); } catch(Error $ex) { print_r($ex->getMessage()); } echo "<pre>"; print_r($results); 工具旨在通过使用提供AND grep:

agrep

在你的情况下,你可以运行

 agrep 'pattern1;pattern2' file

PS1:对于当前目录,您只需find . -type f -exec agrep 'toto;tata' {} \; #apply -l to display the file names
PS2:不幸的是agrep不支持-R选项。