0

Search of files by means of keywords with a formatted output

I'd like to find any kind of file by means of keywords and a formatted output, so I'm trying to use the command "awk, but I receive this error message:

% find . -type f -exec grep -if /home/peppespe/Documents/1265/keywords.txt  '{}' ';' -exec ls -laith '{}' ';' -exec md5sum '{}' | awk '{ print "md5 = " $1 }'  ';' -exec sha1sum '{}' | awk '{ print "sha1 = " $1 }' ';'
find: manca l'argomento per «-exec»
awk: linea progr.:1: fatale: non riesco ad aprire file `;' in lettura (File o directory non esistente)
awk: linea progr.:1: fatale: non riesco ad aprire file `;' in lettura (File o directory non esistente)
4

1 回答 1

2

您正在尝试在 -exec 的参数中使用管道,但它们在调用 find 之前由 shell 解析。结果是您使用 ';' 调用 awk 作为参数(它认为这是一个要打开的文件)。

您可能希望从 grep 输出文件列表并从那里继续,而不是一长串 -exec。像这样的东西(未经测试)

grep -rifl keywords.txt | while read x; do
    echo "$x md5=$(md5sum $x) sha1=$(sha1sum $x)"
done

这与您正在做的格式有点不同,但也许您可以从那里使用它。:-)

于 2013-11-07T16:09:50.087 回答