encontrar arquivo lê-lo e procurar por identificador específico

0

Estou tentando descobrir em quais arquivos alguns identificadores específicos estão sendo usados. Eu sei o nome do arquivo e sei o identificador, portanto, eu uso o seguinte comando para alcançar o resultado desejado:

find ./ -name "configuration.php" -print | xargs cat | grep db_userXYZ

O único problema é que estou perdendo o nome do arquivo. Eu vejo que db_userXYZ está sendo usado em algum lugar, mas o comando acima, não me diz em qual arquivo. A saída seria algo como:

$this->db_user = 'db_userXYZ';
$this->db_name = 'db_XYZ';

Alguma sugestão?

    
por w0rldart 28.08.2014 / 11:38

1 resposta

3

Tente:

find ./ -name "configuration.php" -exec grep db_userXYZ /dev/null {} +

POSIX definido localizar -exec utility_name [argument ...] {} + :

If the primary expression is punctuated by a plus sign, the primary shall always evaluate as true, and the pathnames for which the primary is evaluated shall be aggregated into sets. The utility utility_name shall be invoked once for each set of aggregated pathnames. Each invocation shall begin after the last pathname in the set is aggregated, and shall be completed before the find utility exits and before the first pathname in the next set (if any) is aggregated for this primary, but it is otherwise unspecified whether the invocation occurs before, during, or after the evaluations of other primaries. If any invocation returns a non-zero value as exit status, the find utility shall return a non-zero exit status. An argument containing only the two characters "{}" shall be replaced by the set of aggregated pathnames, with each pathname passed as a separate argument to the invoked utility in the same order that it was aggregated. The size of any set of two or more pathnames shall be limited such that execution of the utility does not cause the system's {ARG_MAX} limit to be exceeded. If more than one argument containing only the two characters "{}" is present, the behavior is unspecified.

Se a sua opção grep suporta -H ( -H não está definida por POSIX grep ), você pode usar:

find ./ -name "configuration.php" -exec grep -H db_userXYZ {} +
    
por 28.08.2014 / 11:40