3

I have a directory that is populated every 30 mins with a text file, each day I need to grep the line with "Quality data" on it but I only want to grep from the 10 most recent files. How can I tell grep to only look in files created within the last 5 hours?

Mel
  • 31
  • 1
  • 2

1 Answers1

6

You can use find to return only the files created in the last 5 hours and use its exec function to grep from them:

find [PATH_OF_DIRECTORY] -type f -cmin -300 -exec grep "Quality data" {} \;

where -cmin -300 means "created in the last 300 minutes (5h)"