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
Leave a Comment
|
December 7th, 2006 at 11:16 pm
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 :
December 7th, 2006 at 11:25 pm
man grep
hehehe.
References :
December 7th, 2006 at 11:25 pm
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 :