我试图找到一个命令或创建一个Linux脚本,它可以执行这两个组件并列出otuput
find . -name '*bills*' -print这个打印了所有的文件
./may/batch_bills_123.log
./april/batch_bills_456.log
..根据这个结果,我想对一个单词执行grep,我现在手动执行这个操作。
grep 'put' ./may/batch_bill_123.log 并获取
sftp > put oldnet_1234.lst我希望得到文件名和它的匹配。
./may/batch_bills_123.log sftp > put oldnet_1234.lst
..
..
and so on... 有什么想法吗?
发布于 2014-02-13 21:12:44
您正在grep中寻找-H选项。
find . -name '*bills*' -exec grep -H "put" {} \;这是解释
-H, --with-filename
Print the filename for each match.发布于 2014-02-13 21:18:33
既然问题更清楚了,您可以在一个grep中完成这个任务。
grep -R --include "*bills*" "put" .带相关旗帜
-R, -r, --recursive
Read all files under each directory, recursively; this is
equivalent to the -d recurse option.
--include=GLOB
Search only files whose base name matches GLOB (using wildcard
matching as described under --exclude).发布于 2020-05-08 20:14:42
或者甚至更容易
grep -R put **/*bills*** glob语法意味着“目录的任何深度”。它将在Zsh工作,我认为最近版本的Bash也是如此。
https://stackoverflow.com/questions/21763904
复制相似问题