Extract the lines between two dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract the lines between two dates
# 1  
Old 07-05-2012
Data 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 that time and refer with time available in sql output file "2012-07-01 19:15:01" & "2012-07-01 19:30:01" and extract the lines between these two times "2012-07-01 19:15:01" & "2012-07-01 19:30:01"
how can i achieve this pl. help .. thanks in advance.

Sample SQL file and will be appended every 15 minutes
Code:
SQL> SQL> SQL> SQL>
RECOVER_TIME
-------------------
2012-07-01 19:15:01
SQL> ORA-00279: change 38528825790 generated at 07/01/2012 11:57:30 needed for
thread 1
ORA-00289: suggestion : /oracle/XXX/oraarch/XXXarch1_AAA_XXXXXXXX.dbf
ORA-00280: change 38528825790 for thread 1 is in sequence #AAA


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log
'/oracle/XXX/oraarch/XXXarch1_AAA_XXXXXXXX.dbf'
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3


ORA-00308: cannot open archived log
'/oracle/XXX/oraarch/XXXarch1_AAA_XXXXXXXX.dbf'
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3


SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
mesg: 0803-003 Cannot find the terminal.
[YOU HAVE NEW MAIL]

SQL*Plus: Release 11.2.0.2.0 Production on Sun Jul 1 22:30:01 2012

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

SQL> Connected.
SQL> SQL> SQL> SQL>
RECOVER_TIME
-------------------
2012-07-01 19:30:01
SQL> ORA-00279: change 38528825790 generated at 07/01/2012 11:57:30 needed for
thread 1
ORA-00289: suggestion : /oracle/XXX/oraarch/XXXarch1_AAA_XXXXXXXX.dbf
ORA-00280: change 38528825790 for thread 1 is in sequence #AAA

I need out put to be displayed as below:
Code:
SQL> ORA-00279: change 38528825790 generated at 07/01/2012 11:57:30 needed for
thread 1
ORA-00289: suggestion : /oracle/XXX/oraarch/XXXarch1_AAA_XXXXXXXX.dbf
ORA-00280: change 38528825790 for thread 1 is in sequence #AAA


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log
'/oracle/XXX/oraarch/XXXarch1_AAA_XXXXXXXX.dbf'
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3


ORA-00308: cannot open archived log
'/oracle/XXX/oraarch/XXXarch1_AAA_XXXXXXXX.dbf'
ORA-27037: unable to obtain file status
IBM AIX RISC System/6000 Error: 2: No such file or directory
Additional information: 3


SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
mesg: 0803-003 Cannot find the terminal.
[YOU HAVE NEW MAIL]

SQL*Plus: Release 11.2.0.2.0 Production on Sun Jul 1 22:30:01 2012

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

SQL> Connected.
SQL> SQL> SQL> SQL>
RECOVER_TIME
-------------------

Moderator's Comments:
Mod Comment edit by bakunin: this might have happened on an AIX system but it is hardly related to the OS. I am going to transfer this thread to the Scripting board therefore.

For clarification: The OS is implicitly AIX ant the shell ksh.

Last edited by bakunin; 07-05-2012 at 07:05 AM..
# 2  
Old 07-05-2012
Code:
strt='2012-07-01 19:15:01'
end='2012-07-01 19:30:01'
awk '/'"$strt"'/{p=1;next} /'"$end"'/{p=0}p' inputfile

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

ksh sed - Extract specific lines with mulitple occurance of interesting lines

Data file example I look for primary and * to isolate the interesting slot number. slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'` Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Discussion started by: popeye
2 Replies

3. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

4. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

5. Shell Programming and Scripting

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... child process 2588 still did not exit, sending a... (2 Replies)
Discussion started by: Reddy482
2 Replies

6. UNIX for Dummies Questions & Answers

Extract dates from file name.

Hi All, I have files with names as us_Gec1_wk_01to01_2008.TXT ad_EngEnt_wk_01to10_2008.TXT br_EngMov_wk_01to10_2008.TXT Over here, I need to extract the dates and the year and store them in variables. How can I achieve the same in bash. In case of ad_EngEnt_wk_01to10_2008.TXT ... (3 Replies)
Discussion started by: Swapna173
3 Replies

7. Shell Programming and Scripting

Extract loglines between two dates

Hi all, this is my first post, and i want to say hello to everyone in there. I've a little problem for you all :). I have a log like this: 38714 07/02/09 00:01:36 nsrd web2consolidato:D:\ done saving to pool 'SISTMSW0060' (Q09480) 32 GB 38752 07/02/09 00:01:37 nsrd /dev/rmt/STK0.2.10.5... (5 Replies)
Discussion started by: koma
5 Replies

8. Shell Programming and Scripting

data extract from dates

I have a 1 GB file.I want to take the information for last one month from that file. Say i want to extract data from May 1st. File contents below. 193.135.218.124 - - "GET /jsp/acafai/supplier/notification.htm HTTP/1.1" 200 38531 193.135.218.124 - - "GET /images/2_aca_fai.gif HTTP/1.1"... (5 Replies)
Discussion started by: Krrishv
5 Replies

9. 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

10. 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
Login or Register to Ask a Question