How to search log file from a date

Hi All,

I want to grep through all the log files created from 20th August. How do I do that? My script will run everyday. So it will take current date as To_Date.

My log file name looks like - applog-2012-08-20-000001....applog-2012-08-20-000002...etc.

Thanks in advance.

This should work for you so you can grep(i.e. search) for what you need:

current_date="2012-08-20"
for x in `ls applog-${current_date}*`
do
  grep .............. ${x}
done
ls applog-2012-08-20* -1 | xargs -i grep "your pattern" {} 

@complex.invoke placing arguments after the ls filelist is bad form, it is likley to result in "File -1 does not exist" errors with many ls implementations.

1 Like

I think I did not make my requirement clear.
The answers seems all looking for 20th August not more than that.
Let me give you one example:-

Suppose today is 28th August, So To_Date is 28th August.
My From_Date is 20th August.

So I want to grep all the log from 20th to 28th August.

Now when the same grep command runs tomorrow(29th August) the grep will look for all the logs from 20th to 29th August, like that.

Thanks,
Kousik

If your using the bash shell try:

printf "%x\n" applog-2012-08-{20..29}-* | xargs grep "your pattern"

If you need this to work for any future date (e.g. 15/09/2012 or 1/1/2013) we will need some more information about what OS and shell (+ version numbers) you are using.