How can I search the word in the specific date files by using grep command in the Unix server?

Few hundreds files are available in Unix server and files do not follow any naming convention.
I want to search one word in all the files which were created in the specific date/period by using grep command. How can I do that?

Ex:
Required word is "ABC Inc" and want to search in the files which were created on 6-Dec-2006 or
Required word is "ABC Inc" and want to search in the files which were created in the period
5-Dec-2006 to 8-Dec-2006.

Try this:

find . -ctime +1 -exec grep -l "ABC Inc" {} \;

This will find you all files(it will name only files because of "l" option) which were created/modified 1 day ago (given by +1 )

man grep for more details. I hope it helps

3 Responses

  1. Raven Says:

    Sounds kind of complicated for a 1-line shell command, especially using only grep.
    Personally I'd write a quick perl script to do it.

    I'd write it for you now, but I'm lazy right now, maybe later.
    References :

  2. danieltalsky Says:

    man grep

    hehehe.
    References :

  3. Aditya Sehgal Says:

    Try this:

    find . -ctime +1 -exec grep -l "ABC Inc" {} \;

    This will find you all files(it will name only files because of "l" option) which were created/modified 1 day ago (given by +1 )

    man grep for more details. I hope it helps
    References :

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Posted on August 15th, 2008 by admin and filed under unix |

|