Tom*_*Tom 11 linux bash grep cat
我在 Ubuntu 下使用 bash。
目前这适用于当前目录:
catdoc *.doc | grep "specificword"
Run Code Online (Sandbox Code Playgroud)
但是我有很多带有 .doc 文件的子目录。
我怎样才能递归地搜索“特定词”?
use*_*686 14
使用find递归搜索:
find -name '*.doc' -exec catdoc {} + | grep "specificword"
Run Code Online (Sandbox Code Playgroud)
这也将输出文件名:
find -name '*.doc' | while read -r file; do
catdoc "$file" | grep -H --label="$file" "specificword"
done
Run Code Online (Sandbox Code Playgroud)
(通常我会使用find ... -print0 | while read -rd "" file,但可能有 0.0001% 的可能性是必要的,所以我不再关心了。)