lines between two dates in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting lines between two dates in a file
# 1  
Old 11-30-2010
lines between two dates in a file

Hi Every body

I had a data in file as shown..
Now i want to get the data and insert into other file but between the two date ranges or from a past date to current date..Please Guide me in doing that..

Below is the data that looks like...

[Mon Nov 15 11:21:44 2010] [warn] child process 2588 still did not exit, sending a SIGTERM
[Mon Nov 15 11:21:44 2010] [warn] child process 2616 still did not exit, sending a SIGTERM
[Mon Nov 15 11:21:46 2010] [error] child process 2532 still did not exit, sending a SIGKILL
[Mon Nov 15 11:21:46 2010] [error] child process 2588 still did not exit, sending a SIGKILL
[Mon Nov 15 11:21:46 2010] [error] child process 2616 still did not exit, sending a SIGKILL
[Mon Nov 15 11:21:47 2010] [notice] caught SIGTERM, shutting down
[Mon Nov 15 11:22:13 2010] [notice] IBM_HTTP_Server/6.0.2.29 Apache/2.0.47
[Mon Nov 15 11:22:13 2010] [notice] Core file limit is 0; core dumps will be not be written for server crashes
[Mon Nov 15 13:49:36 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/crossdomain.xml
[Mon Nov 15 13:52:31 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/crossdomain.xml
[Wed Nov 17 20:11:47 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/robots.txt
[Wed Nov 17 20:11:48 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/robots.txt
[Thu Nov 18 11:31:28 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/https:
[Fri Nov 26 07:10:22 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/robots.txt
[Sun Nov 28 17:36:27 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/Login, referer:
[Sun Nov 28 17:36:31 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/assets, referer:
[Tue Nov 30 04:38:30 2010] [error] File does not exist: /opt/IBM/IHS/htdocs/en_US/robots.txt


Now lets say if want to get text between two date Nov 17 to Nov 28...
How can i get that...Smilie
# 2  
Old 11-30-2010
Code:
 sed '/pattern/r second_file' file

Check if -i in place is supported by your sed
# 3  
Old 11-30-2010
Is the other file of a similar format (ie leading date+time) and if so, should the extracted block of lines be merged with the records in the other file in date order, or just appended to the end?

If your after something quite simple and both the from and to dates exist in the file a simple sed script will get the data:

Code:
 sed -n '/Nov 17/,/Nov 26/p' logfile

Do you have GNU date on your system? Try:

Code:
 $ date --date "Nov 18"

Can we assume the files are already sorted in date+time order?

Last edited by Chubler_XL; 11-30-2010 at 10:00 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - printing new lines based of 2 dates

I have some test data that is seperated out into annual records, each record has a start date (COL7), an end date (COL8) and a maturity date (COL18) - What I need to do is ensure that there is one record to cover each year right up until Maturity date (COL18). In the first group of the below... (10 Replies)
Discussion started by: Ads89
10 Replies

2. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Replacing the Dates in a file

Hello Gurus, I'm beginner in Shell scripting. I got a requirement to write a script. I have a file with below (similar) content If you can observe above content, there are many date values existed (with different dates) in a format: ddMonyyyy I have to write replace all these... (7 Replies)
Discussion started by: raghu.iv85
7 Replies

4. UNIX for Advanced & Expert Users

How to get the Missing dates between two dates in the table?

Hi Am Using Unix Ksh ... I have a Table called date select * from date ; Date 01/02/2013 06/02/2013 I need the output as Missing Date 01/02/2013 02/02/2013 03/02/2013 04/02/2013 05/02/2013 06/02/2013 (2 Replies)
Discussion started by: Venkatesh1
2 Replies

5. Shell Programming and Scripting

Extract the lines between two dates

Dear experts I am new bee to scripting... Pl. help me getting the lines between two strings. I am getting the oracle sql output as below. and would like to get the time from system date compare with the date in sql output file and extract the lines. if system time is 2012-07-01 19:15:00 get... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

6. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

7. Shell Programming and Scripting

How to processing the log file within certain dates based on the file name

Hi I am working on the script parsing specific message "TEST" from multiple file. The log file name looks like: N3.2009-11-26-03-05-02.console.log.tar.gz N4.2009-11-29-00-25-03.console.log.tar.gz N6.2009-12-01-10-05-02.console.log.tar.gz I am using the following command: zgrep -a --text... (1 Reply)
Discussion started by: shyork2001
1 Replies

8. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. UNIX for Dummies Questions & Answers

Subtract two dates in different lines

Hi Friends :) I have a long file having fields in the form : Field1 yy/mm/dd hh:mm:ss Duration(Sec) line 1) 123123 05/11/30 12:12:56 145 line 2) 145235 05/11/30 12:15:15 30 line 3) 145264 05/11/30 13:14:56 178 . . I want to... (1 Reply)
Discussion started by: vanand420
1 Replies

10. UNIX for Dummies Questions & Answers

Formatting dates in a file

Hi! Sitting with a headache this morning and can't get the brain around it! I have a file with 32000 lines that needs to be inserted onto a database. My problem is with the following: First part between bars is a date and second some identifiers |19511108|0001417| |19481024|0001439|... (6 Replies)
Discussion started by: maverick
6 Replies
Login or Register to Ask a Question