Isso porque grep
não pode ler nomes de arquivos para pesquisar a partir da entrada padrão. O que você está fazendo é imprimir os arquivos nomes que contêm XYZ
. Use a opção find
-exec
em vez disso:
find . -name "*ABC*" -exec grep -H 'XYZ' {} +
De man find
:
-exec command ;
Execute command; true if 0 status is returned. All following
arguments to find are taken to be arguments to the command until
an argument consisting of ';' is encountered. The string '{}'
is replaced by the current file name being processed everywhere
it occurs in the arguments to the command, not just in arguments
where it is alone, as in some versions of find.
[...]
-exec command {} +
This variant of the -exec action runs the specified command on
the selected files, but the command line is built by appending
each selected file name at the end; the total number of invoca‐
tions of the command will be much less than the number of
matched files. The command line is built in much the same way
that xargs builds its command lines. Only one instance of '{}'
is allowed within the command. The command is executed in the
starting directory.
Se você não precisar das linhas reais correspondentes, mas apenas da lista de nomes de arquivos que contém pelo menos uma ocorrência da string, use isso:
find . -name "*ABC*" -exec grep -l 'XYZ' {} +