I am trying to find all files that start with a certain name, then go through each file to find lines that contains a string, then only print out the last line of each file that contain the string. Step by step, I first find all files in my directory that start with "A123"
find . -name 'A123*'
then get each line in the file that contains "Trial"
find . -name 'A123*' -exec grep 'Trial' {} \;
and then from here I only want to print the last line,
find . -name 'A123*' -exec grep 'Trial' {} | tail -1 \;
however, this last command does not work. How do I fix this to get what I am trying to get?