I have multiple subdirectories, and each has a log file that I want to check, but I only want to check the log files that have not reached the “completed” state. The last line of a completed log file contains the word “completed”. These log files could be large (10k+ lines), so I know grep might not be ideal.
I want to print the last line of each log file that hasn’t completed yet.
find ~+ -iname "log.out" -exec printf '%s' {} ; | xargs -0 grep -L completed | xargs tail -n 1
This is what I have so far. This works, but becomes very slow as the number of subdirectories and log files increases. Is there a better way?
pocho is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Isn’t this all you need?
find ~+ -iname "log.out" -exec tail -n 1 {} + | grep -v completed