3

I have a folder with huge number of files and I want to extract files present with certain text XYZ created within a date range.

I found this to search files within a date range, but unsure how to club it with the specific text filter.

find /MY_DIR/ -newermt "2017-12-01" ! -newermt "2021-01-31"

2 Answers 2

3

The proper way is to add an -exec option.

find /MY_DIR/ -type f -newermt "2017-12-01" ! -newermt "2021-01-31" -exec grep -l XYZ {} +

Also added -type f option to only look for regular files, not directories, sockets, etc.

0

If you would like to find some text within those files just use grep like this:

grep -i "XYZ" `find /MY_DIR/ -newermt "2017-12-01" ! -newermt "2021-01-31"`

The -i switch makes it case insensitive.

The grep at the start of the line will look for text in files.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .