bash - grep : how to put the filename before each match, 当文件来自管道时?

标签 bash shell find grep pipe

通过这一行,我总是在匹配之前得到 Standardinput 作为文件名。
有没有办法重写这一行以获取匹配项前面的真实文件名?

find . -name '*.doc' -exec wvText {} \; | grep -rH --color word

最佳答案

find . -name '*.doc' | xargs -d"\n" grep -rH --color word

啊,那不处理其中的 wvText 位。也许是这样的:

for doc in `find . -name '*.doc'`; do wvText "$doc" | grep -rH --color word | \
sed "s;^;$doc: ;"; done

关于bash - grep : how to put the filename before each match, 当文件来自管道时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7840785/

相关文章:

linux - 设置捕获组的长度

java - 我正在尝试通过java编程将Sqoop从oracle导入到hdfs

sql-server - 如何编写 bash 和 sql 文件来设置 postgres 用户?

c - C shell 管系统

shell - 将字符串拆分为命令行参数

linux - 查找命令语法

linux - 如何编写在程序内部运行的命令脚本

ruby - Runy Open3.popen3 从命令行输入子进程

linux - 使用 Linux 命令查找并替换

linux - 如何在不包含文件夹本身的情况下查找文件夹中的所有文件