Shell Scripting
Hii,
I want to write a shell script so that it selects a pattern from a file and copies only that part. In this file I have to search for "Errors" pattern. If this is present I must check if it contains "ORA" in the subsequent line. If this is present then I have to copy from a line previous to the "Errors" line till the next date. How can this be accomplished. Can anyone Help? The file is as follows. Fri Aug 31 13:08:43 2007 Errors in file /home/oracle10/admin/EAIDB/bdump/eaidb_psp0_29199.trc: ORA-27300: OS system dependent operation:fork failed with status: 11 ORA-27301: OS failure message: Resource temporarily unavailable ORA-27302: failure occurred at: skgpspawn5 Wed Sep 5 16:59:25 2007 Thread 1 advanced to log sequence 5437 Current log# 1 seq# 5437 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo01.log Wed Sep 5 17:08:09 2007 Thread 1 advanced to log sequence 5438 Current log# 4 seq# 5438 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo4.log Wed Sep 5 17:13:55 2007 Thread 1 advanced to log sequence 5439 Current log# 2 seq# 5439 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo02.log Wed Sep 5 17:17:07 2007 Thread 1 advanced to log sequence 5440 Current log# 3 seq# 5440 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo03.log Wed Sep 5 17:17:29 2007 Thread 1 advanced to log sequence 5441 Current log# 5 seq# 5441 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo5.log Wed Sep 5 17:19:29 2007 Thread 1 advanced to log sequence 5442 Current log# 1 seq# 5442 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo01.log Wed Sep 5 17:28:32 2007 Thread 1 advanced to log sequence 5443 Wed Sep 5 23:32:42 2007 Errors in file /home/oracle10/admin/EAIDB/bdump/eaidb_j000_17397.trc: ORA-12012: error on auto execute of job 8874 ORA-20000: ORA-20000: Content of the tablespace specified is not permanent or tablespace name is invalid ORA-06512: at "SYS.PRVT_ADVISOR", line 1624 ORA-06512: at "SYS.DBMS_ADVISOR", line 186 ORA-06512: at "SYS.DBMS_SPACE", line 1338 ORA-06512: at "SYS.DBMS_SPACE", line 1554 Mon Sep 3 16:01:49 2007 Errors in file /home/oracle10/admin/EAIDB/udump/eaidb_ora_10177.trc: ORA-07445: exception encountered: core dump [skgfqio()+112] [SIGBUS] [Invalid address alignment] [0x9FFFFFFFFFF9FF50] [] [] Mon Sep 3 16:01:51 2007 Errors in file /home/oracle10/admin/EAIDB/udump/eaidb_ora_10177.trc: ORA-07445: exception encountered: core dump [$cold_kghfrf()+2288] [SIGSEGV] [Address not mapped to object] [0x000010026] [] [ ] ORA-04030: out of process memory when trying to allocate 753136 bytes (pga heap,kco buffer) ORA-07445: exception encountered: core dump [skgfqio()+112] [SIGBUS] [Invalid address alignment] [0x9FFFFFFFFFF9FF50] [] [] Mon Sep 3 16:01:53 2007 Errors in file /home/oracle10/admin/EAIDB/udump/eaidb_ora_10177.trc: ORA-07445: exception encountered: core dump [$cold_kghfrf()+2288] [SIGSEGV] [Address not mapped to object] [0x000010026] [] [ ] ORA-04030: out of process memory when trying to allocate 753136 bytes (pga heap,kco buffer) ORA-07445: exception encountered: core dump [$cold_kghfrf()+2288] [SIGSEGV] [Address not mapped to object] [0x000010026] [] [ ] ORA-04030: out of process memory when trying to allocate 753136 bytes (pga heap,kco buffer) ORA-07445: exception encountered: core dump [skgfqio()+112] [SIGBUS] [Invalid address alignment] [0x9FFFFFFFFFF9FF50] [] [] Mon Sep 3 16:02:39 2007 Errors in file /home/oracle10/admin/EAIDB/bdump/eaidb_psp0_29199.trc: ORA-27300: OS system dependent operation:fork failed with status: 11 ORA-27301: OS failure message: Resource temporarily unavailable ORA-27302: failure occurred at: skgpspawn5 Mon Sep 3 16:02:40 2007 |
Hello Is my Question too dificult to understand or solve
|
Quote:
And no, your question isn't difficult but you wrote Quote:
A) you want to write the script. In that case you do the research (http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html, http://www.tldp.org/LDP/Bash-Beginne...tml/index.html), post what script you've got and we help you after that. This is the preferred way since you actually learn something. B) you require a fellow LQ member to write the script for you (needs only a "while" loop and two tests). In that case you rephrase your demand as a polite question and exercise patience. |
Moved: This thread is more suitable in the programming forum and has been moved accordingly to help your thread/question get the exposure it deserves.
|
You could probably do it using either sed or awk.
If you used sed, it will probably be a lot easier coming to a solution if you inserted an empty line before each date. Code:
$ sed -r '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/i\ $ sed -rn '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/,/^$/{ ... } Then you could add each line to the working buffer inside the range and when you reach /^$/, test for the pattern '\nORA'. If it is found, print out the working buffer. You might want to test this out: Code:
$ sed -r '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/i\ Here I'll cheat: Code:
echo >>junk |
Thanks JSCHIWAL. But I could not understand the program can u help me out with it? Also it should print only if both Errors and ORA patterns are found assuming that in the file there are line which has only ORA patterns also. How do I modify the same for that. The file is as follows.
Mon Jul 16 20:28:01 2007 Thread 1 advanced to log sequence 2330 Current log# 3 seq# 2330 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo03.log Mon Jul 16 20:33:16 2007 Thread 1 advanced to log sequence 2331 Current log# 5 seq# 2331 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo5.log Mon Jul 16 20:38:36 2007 Thread 1 advanced to log sequence 2332 Current log# 1 seq# 2332 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo01.log Mon Jul 16 20:43:36 2007 Thread 1 advanced to log sequence 2333 Current log# 4 seq# 2333 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo4.log Mon Jul 16 20:49:00 2007 Thread 1 advanced to log sequence 2334 Current log# 2 seq# 2334 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo02.log Mon Jul 16 20:54:18 2007 Thread 1 advanced to log sequence 2335 Current log# 3 seq# 2335 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo03.log Mon Jul 16 20:59:32 2007 Thread 1 advanced to log sequence 2336 Current log# 5 seq# 2336 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo5.log Mon Jul 16 21:04:50 2007 Thread 1 advanced to log sequence 2337 Current log# 1 seq# 2337 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo01.log Mon Jul 16 21:09:52 2007 Thread 1 advanced to log sequence 2338 Current log# 4 seq# 2338 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo4.log Mon Jul 16 21:15:13 2007 Thread 1 advanced to log sequence 2339 Current log# 2 seq# 2339 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo02.log Mon Jul 16 21:20:32 2007 Thread 1 advanced to log sequence 2340 Current log# 3 seq# 2340 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo03.log Mon Jul 16 21:25:48 2007 Thread 1 advanced to log sequence 2341 Current log# 5 seq# 2341 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo5.log Mon Jul 16 21:31:05 2007 Thread 1 advanced to log sequence 2342 Current log# 1 seq# 2342 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo01.log Mon Jul 23 22:00:30 2007 Errors in file /home/oracle10/admin/EAIDB/bdump/eaidb_j000_19631.trc: ORA-12012: error on auto execute of job 8874 ORA-13607: The specified task or object ORA-13607: The specified task or object SYS_AUTO_SPCADV_2930162372007 already exists ORA-06512: at "SYS.PRVT_ADVISOR", line 3902 ORA-06512: at "SYS.DBMS_ADVISOR", line 102 ORA-06512: at "SYS.DBMS_SPACE", line 1450 ORA-06512: at "SYS.DBMS_SPACE", line 1554 already exists Mon Jul 23 23:19:07 2007 Thread 1 advanced to log sequence 2364 Current log# 2 seq# 2364 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo02.log Tue Jul 24 21:31:59 2007 Thread 1 advanced to log sequence 2365 Current log# 3 seq# 2365 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo03.log Wed Jul 25 16:26:37 2007 Thread 1 advanced to log sequence 2366 Current log# 5 seq# 2366 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo5.log Thu Jul 26 11:15:51 2007 Shutting down instance: further logons disabled Fri Aug 10 16:13:16 2007 ORA-3297 signalled during: ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 5000M... Fri Aug 10 16:13:22 2007 ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 6000M ORA-3297 signalled during: ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 6000M... Fri Aug 10 16:13:28 2007 ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 7000M Fri Aug 10 16:13:28 2007 ORA-3297 signalled during: ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 7000M... Fri Aug 10 16:13:34 2007 ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 8000M ORA-3297 signalled during: ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 8000M... Fri Aug 10 16:13:40 2007 ALTER DATABASE DATAFILE '/Softwares/oracle10/oradata/EAIDB/eaidata01b.dbf' RESIZE 9000M Fri Aug 10 19:59:09 2007 Errors in file /home/oracle10/admin/EAIDB/udump/eaidb_ora_17192.trc: ORA-07445: exception encountered: core dump [kcsgrsn()+400] [SIGSEGV] [Invalid permissions for mapped object] [0x0000006EC] [ ] [] ORA-03113: end-of-file on communication channel ORA-03113: end-of-file on communication channel Fri Aug 10 19:59:10 2007 Errors in file /home/oracle10/admin/EAIDB/udump/eaidb_ora_17192.trc: ORA-07445: exception encountered: core dump [kcsgrsn()+400] [SIGSEGV] [Invalid permissions for mapped object] [0x0000006EC] [ ] [] ORA-07445: exception encountered: core dump [kcsgrsn()+400] [SIGSEGV] [Invalid permissions for mapped object] [0x0000006EC] [ ] [] ORA-03113: end-of-file on communication channel ORA-03113: end-of-file on communication channel Fri Aug 10 20:05:04 2007 Thread 1 advanced to log sequence 2694 Current log# 2 seq# 2694 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo02.log Fri Aug 10 20:05:24 2007 Thread 1 advanced to log sequence 2695 Current log# 3 seq# 2695 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo03.log Fri Aug 10 20:05:42 2007 Thread 1 advanced to log sequence 2696 Current log# 5 seq# 2696 mem# 0: /Softwares/oracle10/oradata/EAIDB/redo5.log Mon Aug 20 22:43:04 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:04 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:04 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:04 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:04 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:04 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:04 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:05 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:05 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:05 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:05 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:05 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 Mon Aug 20 22:43:05 2007 ORA-1654: unable to extend index EAIMGR.SYS_C0010530 by 1024 in tablespace TCS_SLV_DATA01 |
Here's an AWK solution.
Code:
awk -F '\n' '/Errors/{for(i=1;i<=NF;i++){ Code:
RS='(Mon|Tue|Wed|Thu|Fri|Sat|Sun)' Code:
-F '\n' Code:
/Errors/{...} Code:
{for(i=1;i<=NF;i++){ Code:
rt=RT I hope it makes sense enough for you to figure out. PS: You can add something like Code:
ORS='-------------\n' here's the output using your second sample as a source: Code:
awk -F '\n' '/Errors/{for(i=1;i<=NF;i++){ Code:
awk -F'\n' '{for (i=1;i<=NF;i++) |
[quote=sagarbsa;2912509]Thanks JSCHIWAL. But I could not understand the program can u help me out with it?
Code:
$ sed -r '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/i\ # Matches lines starting with a date, and inserts a blank line before it. This makes selecting a range easier. Since we used the "H" command, the working register contains multiple lines, so the pattern from both lines of input are present and can be tested for. Code:
echo >>junk |
this does it...
Code:
#!/usr/bin/perl |
Thanks a lot Dudes. Now the program is working fine. But Wanted to know what does "/^$/" and "x" implies.
|
Quote:
"x" exchanges the Hold buffer with pattern space. The pattern space is where lines are read into. |
Thanks JSCHIWAL. The program is done now. Can you suggest some good awk and sed tutorial.
|
|
Hii
I tried to run the above program inHP-UX in ksh. When I tried to run the awk program given above it gave the following Error. awk: Input line Mon Jul 16 20:28:01 cannot be longer than 3,000 bytes. The source line number is 4. And for the sed program above I got the error stating sed: illegal option -- r sed: illegal option -- r any solutions |
Probably a different ver. of "awk".
On my box (SimplyMEPIS 6.0): Code:
$ awk --version It is likely that HP-UX is running something like nawk. Why don't you can check the ver. on both machines & post back, please? |
All times are GMT -5. The time now is 05:52 PM. |