Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux bash:筛选不搜索的文件_Linux_Bash_Shell - Fatal编程技术网

Linux bash:筛选不搜索的文件

Linux bash:筛选不搜索的文件,linux,bash,shell,Linux,Bash,Shell,我创建了一个脚本,用于在指定目录中搜索指定关键字: find $directory -type f -name "*.properties" -exec grep -Fi "$keyword" 我面临的问题是,$目录包含两种类型的文件-示例文件和配置文件:config/sample.config。其中sample.config只是一个示例,因此我不想将它们包括在搜索中。 问题是如何从我的结果中排除这些“sample.*”文件?要排除sample.config文件,请添加-在find命令中命名s

我创建了一个脚本,用于在指定目录中搜索指定关键字:

find $directory -type f -name "*.properties" -exec grep -Fi "$keyword"
我面临的问题是,$目录包含两种类型的文件-示例文件和配置文件:config/sample.config。其中sample.config只是一个示例,因此我不想将它们包括在搜索中。
问题是如何从我的结果中排除这些“sample.*”文件?

要排除sample.config文件,请添加
-在find命令中命名sample.config
,例如:

find $(<$SRC) -type f -name "*.properties" ! -name sample.config -exec grep -Fi "$keyword" --color {} +

find$(使用@Nahuel的建议,我对它做了一些修改,它开始为我工作:

find $(<$SRC) -type f -name "*.properties" ! -name "sample.*" -exec grep -Fi "$keyword" --color {} +

find$(可能有一个命令来搜索
$keyword
,使用所有4种文件类型,排除
示例。*

msr-rp-dir1、dir2、dirN-f“\(properties | pl | xml | ini)$”--nf“^sample\。-it”关键字“

  • 使用
    -PAC
    -P-A-C
    去除颜色和行号等以获得纯结果
  • 使用
    -l
    仅列出文件路径并显示分布:计数+百分比

msr.gcc*
是一个单一的exe工具,用于搜索/替换我的开放项目
tools
目录中的文件/管道,具有跨平台版本和操作系统位版本。内置文档:生动的演示,与-findstr-和-grep进行性能比较,测试等。请看主页。

Hi@Nahuel Fouilleul,谢谢或者您的反馈。确切的文件名是config.properties和sample.config.properties。这是否可以将筛选器与and连接起来?是(-a或-and)是隐式的(在-o或-or周围添加括号
\(
\)
)谢谢@Quanamao。我将深入测试此工具,并可能计划在未来的项目中使用它。但是,在这项任务中,我们不允许安装任何第三方。您可以留下您的联系信息以进行任何澄清吗?@faceless:无需安装,只需1个exe文件(
msr.exe
/
msr.gcc48
/
msr.cygwin
)大约1.6MB。我的电子邮件是qualiu@microsoft.com.对于测试,您可以查看/参考:或
windows test.bat
或哦,以上是功能**/functions test.*性能测试结果可以与findstr(windows)和grep(Linux)进行比较:和。希望这个小工具可以帮助您的日常工作。