Is there any way to use pipe within an -exec in find? I don\'t want grep to go through whole file, but only through first line of each file.
find /path/to/di
This does not directly answer your question, but if you want to do some complex operations you might be better off scripting:
for file in $(find /path/to/dir -type f); do echo ${file}; cat $file | head -1 | grep yourstring; done