在 HP-UX 上的许多文件中搜索字符串

Gio*_*nni 4 grep hp-ux recursive portability

我需要仅使用 sh 和系统命令(Perl不是一个选项)来查找目录的哪些文件(文件名中可以​​有空格)包含字符串。

对于一些文件,此命令可以正常工作:

# grep -l word *
file 1
file1
Run Code Online (Sandbox Code Playgroud)

但是如果我有 270k 文件,我会收到以下错误:

#  grep -l word *
sh: /usr/bin/grep: The parameter list is too long.
Run Code Online (Sandbox Code Playgroud)

在 HP-UX 中,xargs命令没有-0选项,所以我不能使用这个:

# find . -print0 |xargs -0 grep -l
xargs: unknown option: -0
Run Code Online (Sandbox Code Playgroud)

你知道我可以使用哪个命令吗?

Mat*_*Mat 5

您可以find像这样使用命令的变体:

find . -type f -exec grep -l word {} \; 
Run Code Online (Sandbox Code Playgroud)