gpt4 book ai didi

linux - 使用两种模式运行递归 grep

转载 作者:太空宇宙 更新时间:2023-11-04 12:27:53 24 4
gpt4 key购买 nike

如何使用此 grep 模式递归搜索目录?我需要将这两个都放在文件字符串的同一行上。我不断收到消息,这是一个目录。我怎样才能让它递归搜索扩展名为 .cfc 的所有文件?

"<cffunction" and "inject="
grep -insR "<cffunction" | grep "inject=" /c/mydirectory/

最佳答案

使用 findexec :

find your_dir -name "*.cfc" -type f -exec grep -insE 'inject=.*<cffunction|<cffunction.*inject=' /dev/null {} +
  • find递归地找到你的 *.cfc 文件并输入 grep , 只选择常规文件 ( -type f )
  • inject=.*<cffunction|<cffunction.*inject=以任意顺序捕获具有您的模式的行
  • {} +确保每次调用 grep最多 ARG_MAX 个文件
  • /dev/null grep 的参数确保输出以文件名为前缀,即使只有一个 *.cfc。文件

关于linux - 使用两种模式运行递归 grep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44119365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com