Get the lines from logfile within start and end date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the lines from logfile within start and end date
# 1  
Old 08-06-2013
Get the lines from logfile within start and end date

Hi guys,

I am having the below logfile,date in yyyy-mm-dd

Code:
 
2013-08-02 *some content*
2013-08-02 *some content*
2013-08-02 *some content*
2013-08-03 *some content*
2013-08-05 *some content*

from the above logfile i need to get the lines between the two timestamps,if i give
Code:
2013-08-02 (start) &  2013-08-05 (end)

i am getting the content.
But wen i give
Code:
2013-08-01  (start) and 2013-08-05 (end)

i didnt get the output.
my reqiurement is even though 2013-08-01 is not there wen i give 2013-08-01 as start date it should calculate and give the lines.
Please help me guys.
I think this can be done through some date manipulation.
# 2  
Old 08-06-2013
Code:
st="2013-08-01"
en="2013-08-03"

awk -v ST="$st" -v EN="$en" '
        {
                V = $1
                gsub ( "-", X, V )
                gsub ( "-", X, ST )
                gsub ( "-", X, EN )
                if ( V >= ST && V <= EN )
                        print
        }
' file.log

# 3  
Old 08-06-2013
Quote:
Originally Posted by Yoda
Code:
st="2013-08-01"
en="2013-08-03"

awk -v ST="$st" -v EN="$en" '
        {
                V = $1
                gsub ( "-", X, V )
                gsub ( "-", X, ST )
                gsub ( "-", X, EN )
                if ( V >= ST && V <= EN )
                        print
        }
' file.log

recommend to move below lines to BEGIN{} part in awk, which will avoid to gsub on each line again.

Code:
                gsub ( "-", X, ST )
                gsub ( "-", X, EN )

These 2 Users Gave Thanks to rdcwayx For This Post:
# 4  
Old 08-07-2013
Hi guys thanks for your reply,
when i run the above script i didnt get any output.

Code:
 
[ 2013-08-02 04:01:23 pid=15642 ppid=15642 ]  Exited the Programme
[ 2013-08-02 03:59:14 pid=15690  ] Exited the Programme, recovery completed
[ 2013-08-03 09:15:37 pid=21374   ] Exited the Programme, recovery completed 
[ 2013-08-03 09:19:49 pid=21773   ] Exited the Programme, recovery 
[ 2013-08-04 09:26:44 pid=22199  ] Exited the Programme, recovery completed

the code i run is
Code:
#!/bin/ksh
st="2013-08-01"
en="2013-08-03"
awk -v ST="$st" -v EN="$en" '
{
V = $1
gsub ( "-", X, V )
gsub ( "-", X, ST )
gsub ( "-", X, EN )
if ( V >= ST && V <= EN )
print
}
' recovery.log

# 5  
Old 08-07-2013
Make V to $2 on your script since your actual file has a [ in the beginning.

Code:
V = $2

This User Gave Thanks to rajamadhavan For This Post:
# 6  
Old 08-07-2013
hi thank u its working fineSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Splitting week start date and end date based on custom period start dates

Below are my custom period start and end dates based on a calender, these dates are placed in a file, for each period i need to split into three weeks for each period row, example is given below. Could you please help out to achieve solution through shell script.. File content: ... (2 Replies)
Discussion started by: nani2019
2 Replies

2. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

3. UNIX for Dummies Questions & Answers

Print start date to end date, given $1 & $2 in ksh

Dear all, I have an user passing 2 parameter 31/03/2015 and 02/04/2015 to a ksh script. How to print the start date to end date. Expected output is : 31/03/2015 01/04/2015 02/04/2015 Note : 1. Im using aix and ksh 2. I have tried to convert the given input into a date, didnt... (0 Replies)
Discussion started by: mr.rajaravi
0 Replies

4. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

5. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

6. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

7. Shell Programming and Scripting

Need to capture all dates between start date and End date.

Hi All, I enter Start date and end date as parameters. I need to capture dates between start date and end date. Please let me know if you have any idea the same. Thanks in advance. Nagaraja Akkivalli. (5 Replies)
Discussion started by: Nagaraja Akkiva
5 Replies
Login or Register to Ask a Question