How to search log file from a date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search log file from a date
# 1  
Old 08-26-2012
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.
# 2  
Old 08-26-2012
This should work for you so you can grep(i.e. search) for what you need:
Code:
current_date="2012-08-20"
for x in `ls applog-${current_date}*`
do
  grep .............. ${x}
done

# 3  
Old 08-26-2012
Code:
ls applog-2012-08-20* -1 | xargs -i grep "your pattern" {}

# 4  
Old 08-26-2012
@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.
This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 08-26-2012
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
# 6  
Old 08-27-2012
If your using the bash shell try:

Code:
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.

Last edited by Chubler_XL; 08-27-2012 at 12:55 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

2. Shell Programming and Scripting

Search for logs traced between specific date and time from log file

HI, I want to search for a logs which are trace between specific date and time from logs file. My logs are generated like this :- Tue Jun 18 05:00:02 EEST 2013 | file_check.sh| Message:script has files to process. Thu Jun 20 05:00:02 EEST 2013 | file_check.sh| Message:script has files to... (5 Replies)
Discussion started by: ketanraut
5 Replies

3. Shell Programming and Scripting

UNIX: Search file between two Date stamps

Hi, I have a requirement to find a file based on date stamp provided by user. In one of the shared location I get data file say “datafile<dataformat>“. And User will provide the date based on which I need to select a file which is 7 days older, if a file not present within 7 days, then I need... (3 Replies)
Discussion started by: santhosh86467
3 Replies

4. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

5. Shell Programming and Scripting

How to search file for a date variable?

Hello, I'm trying to write a ksh script which will allow me to to search for yesterday's date within a rtf file. I just need someway to know if the date is in the file, echo results to a text file, and then mail that out. The format of the date is mm/dd/yyyy. I had to make a variable... (2 Replies)
Discussion started by: ronan1219
2 Replies

6. Shell Programming and Scripting

How to search for file and display by date

I like "ls -ltr". I would like to search for a file in a large directory recursively and and display all the candidates in reverse order. /usr/bin/find . -name \*.txt This works. How do I display the date and sort the file names by the date in reverse order for the entire directory... (1 Reply)
Discussion started by: siegfried
1 Replies

7. Solaris

Search date pattern in application log file

I am viewing a file in vi editor and would like to search for a date pattern. In the log, the timestamp is enclosed in parentheses ''. I am using the '/' option in vi to search for the pattern. log snippet: 000000f4 ServletWrappe I SRVE0242I: : Initialization successful. 000000f4... (3 Replies)
Discussion started by: Vangogh78
3 Replies

8. UNIX for Dummies Questions & Answers

Search for a file with Current Date

Hi, How can we search for a file with current date(sysdate). Actually i want the file name from a directory which was created today(current date). For example i have a dir /home/arch and i have files with name aglito03axyz.datetimestamp in this directory, but all these files were created... (7 Replies)
Discussion started by: sandeep_1105
7 Replies

9. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

10. UNIX for Advanced & Expert Users

find file with date and recursive search for a text

Hey Guyz I have a requirement something like this.. a part of file name, date of modification of that file and a text is entered as input. like Date : 080206 (MMDDYY format.) filename : hotel_rates text : Jim now the file hotel_rates.ZZZ.123 (creation date is Aug 02 2006) should be... (10 Replies)
Discussion started by: rosh0623
10 Replies
Login or Register to Ask a Question