linux - 如何将 find 和 grep 的结果输出为 filename => found

标签 linux bash shell grep

如何将命令 findgrep 的结果合并为以下格式:filename: => string

例如,查找。 -maxdepth 2 -type f -name .env -exec grep 'CURRENT_ENV' {}\; 该命令将在找到 CURRENT_ENV 字符串时向我显示该行,例如CURRENT_ENV=staging。我想按以下方式修改输出:./site1.com: CURRENT_ENV=staging.

我不明白我怎样才能做到这一点。是否可以?

最佳答案

  -H, --with-filename
          Print the file name for each match.  This is the default when
          there is more than one file to search.

http://man7.org/linux/man-pages/man1/grep.1.html

关于linux - 如何将 find 和 grep 的结果输出为 filename => found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51509172/

相关文章:

linux - [: missing `]' error in Unix | shell Script

java - Eclipse 无法在 Linux Mint 中打开,Java 无法在不同目录中打开

linux - 在 Vim 中显示输入击键

bash - $HOME 与 ~ 用于 bash 脚本

c - 使用环境变量执行不同的文件

linux - 如果找到第一个字符为 "<"的行,则打印第一个字符为 ">"的行的第一次出现

linux shell 脚本获取文件夹中 <particular name> 的 <latest file>

linux - 为什么 RCX 不用于将参数传递给系统调用,而是用 R10 代替?

c++ - int main 的返回代码 - 有上限吗?

linux - 模拟 netcat -e