Skip to main content
imported Toby Speight's comment to add /dev/null (or GNU grep -H)
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

One way to approach this is to set up timestamp files to bracket the dates you're looking for:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time

... and then ask find for files that are newer than the start-time but not newer than the end-time:

find . -type f  -newer /tmp/start-time  ! -newer /tmp/end-time

Putting it all together:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time
find . -type f -newer /tmp/start-time  ! -newer /tmp/end-time -name '*.xml' -exec grep JMS111 /dev/null {} +
rm /tmp/start-time /tmp/end-time

This will look for files in the right timeframe with names ending in .xml and then pass those filenames to the grep, fitting in as many as it can per pass. I've added /dev/null as a "file" for grep to search from along with the filenames from find, if any. That way, if there is only one matching file, grep is "forced" to report the matching filename (as /dev/null will never match, it won't be reported).

Your output will be the filenames and matching lines from those files.

One way to approach this is to set up timestamp files to bracket the dates you're looking for:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time

... and then ask find for files that are newer than the start-time but not newer than the end-time:

find . -type f  -newer /tmp/start-time  ! -newer /tmp/end-time

Putting it all together:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time
find . -type f -newer /tmp/start-time  ! -newer /tmp/end-time -name '*.xml' -exec grep JMS111 {} +
rm /tmp/start-time /tmp/end-time

This will look for files in the right timeframe with names ending in .xml and then pass those filenames to the grep, fitting in as many as it can per pass.

Your output will be the filenames and matching lines from those files.

One way to approach this is to set up timestamp files to bracket the dates you're looking for:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time

... and then ask find for files that are newer than the start-time but not newer than the end-time:

find . -type f  -newer /tmp/start-time  ! -newer /tmp/end-time

Putting it all together:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time
find . -type f -newer /tmp/start-time  ! -newer /tmp/end-time -name '*.xml' -exec grep JMS111 /dev/null {} +
rm /tmp/start-time /tmp/end-time

This will look for files in the right timeframe with names ending in .xml and then pass those filenames to the grep, fitting in as many as it can per pass. I've added /dev/null as a "file" for grep to search from along with the filenames from find, if any. That way, if there is only one matching file, grep is "forced" to report the matching filename (as /dev/null will never match, it won't be reported).

Your output will be the filenames and matching lines from those files.

edited body
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

One way to approach this is to set up timestamp files to bracket the dates you're looking for:

touch -dt 201902210000 /tmp/start-time
touch -dt 201902212359.59 /tmp/end-time

... and then ask find for files that are newer than the start-time but not newer than the end-time:

find . -type f  -newer /tmp/start-time  ! -newer /tmp/end-time

Putting it all together:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time
find . -type f -newer /tmp/start-time  ! -newer /tmp/end-time -name '*.xml' -exec grep JMS111 {} +
rm /tmp/start-time /tmp/end-time

This will look for files in the right timeframe with names ending in .xml and then pass those filenames to the grep, fitting in as many as it can per pass.

Your output will be the filenames and matching lines from those files.

One way to approach this is to set up timestamp files to bracket the dates you're looking for:

touch -d 201902210000 /tmp/start-time
touch -d 201902212359 /tmp/end-time

... and then ask find for files that are newer than the start-time but not newer than the end-time:

find . -type f  -newer /tmp/start-time  ! -newer /tmp/end-time

Putting it all together:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time
find . -type f -newer /tmp/start-time  ! -newer /tmp/end-time -name '*.xml' -exec grep JMS111 {} +
rm /tmp/start-time /tmp/end-time

This will look for files in the right timeframe with names ending in .xml and then pass those filenames to the grep, fitting in as many as it can per pass.

Your output will be the filenames and matching lines from those files.

One way to approach this is to set up timestamp files to bracket the dates you're looking for:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time

... and then ask find for files that are newer than the start-time but not newer than the end-time:

find . -type f  -newer /tmp/start-time  ! -newer /tmp/end-time

Putting it all together:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time
find . -type f -newer /tmp/start-time  ! -newer /tmp/end-time -name '*.xml' -exec grep JMS111 {} +
rm /tmp/start-time /tmp/end-time

This will look for files in the right timeframe with names ending in .xml and then pass those filenames to the grep, fitting in as many as it can per pass.

Your output will be the filenames and matching lines from those files.

Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

One way to approach this is to set up timestamp files to bracket the dates you're looking for:

touch -d 201902210000 /tmp/start-time
touch -d 201902212359 /tmp/end-time

... and then ask find for files that are newer than the start-time but not newer than the end-time:

find . -type f  -newer /tmp/start-time  ! -newer /tmp/end-time

Putting it all together:

touch -t 201902210000 /tmp/start-time
touch -t 201902212359.59 /tmp/end-time
find . -type f -newer /tmp/start-time  ! -newer /tmp/end-time -name '*.xml' -exec grep JMS111 {} +
rm /tmp/start-time /tmp/end-time

This will look for files in the right timeframe with names ending in .xml and then pass those filenames to the grep, fitting in as many as it can per pass.

Your output will be the filenames and matching lines from those files.