LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell Scripting (https://www.linuxquestions.org/questions/programming-9/shell-scripting-589021/)

sagarbsa 10-02-2007 10:24 PM

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

sagarbsa 10-03-2007 12:38 AM

Hello Is my Question too dificult to understand or solve

unSpawn 10-03-2007 01:42 AM

Quote:

Originally Posted by sagarbsa (Post 2911369)
Hello Is my Question too dificult to understand or solve

LQ is a volunteer-driven community effort relying on its members to supply answers if and when they want to. If you need on-demand 24/7 coverage, please consider hiring a local Linux guru, else just be patient.


And no, your question isn't difficult but you wrote
Quote:

Originally Posted by sagarbsa (Post 2911266)
I want to write a shell script

which means:
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.

reddazz 10-03-2007 02:07 AM

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.

jschiwal 10-03-2007 02:29 AM

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\
' logfile | ...

That would allow a range like this:
$ 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\
' junk | sed -rn '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/,/^$/{
                                                      /^$/!H
                                                    /^$/{
                                                          x
                                                          /ORA/p
                                                        }
                                                    }'

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 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] [] []

It needs some debugging so that the last entry isn't missed. The input file I used didn't end in a empty line so that range wasn't counted.

Here I'll cheat:
Code:

echo >>junk
$ sed -r '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/i\
' junk | sed -rn '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/,/^$/{
                                                      /^$/!H
                                                    /^$/{
                                                          x
                                                          /ORA/p
                                                        }
                                                    }'

Now the log ends in an empty space and the last entry output.

sagarbsa 10-03-2007 10:12 PM

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

angrybanana 10-04-2007 12:51 AM

Here's an AWK solution.

Code:

awk -F '\n' '/Errors/{for(i=1;i<=NF;i++){
                if ($i~/^ORA/) {
                        print rt$0;rt=RT;next}
                }}{rt=RT}' RS='(Mon|Tue|Wed|Thu|Fri|Sat|Sun)' 'file'

explanation:
Code:

RS='(Mon|Tue|Wed|Thu|Fri|Sat|Sun)'
uses mon-sun as a record separator.
Code:

-F '\n'
Makes '\n' the field separator (each line is a field)
Code:

/Errors/{...}
checks if the term "Errors" is in the record (the block between each Mon-Sun found) If it's found it runs the code.
Code:

{for(i=1;i<=NF;i++){
                if ($i~/^ORA/) {
                        print rt$0;rt=RT;next}

loops from 1 to NF (number of fields). Basically it's scanning all fields, checks if the field starts with ORA. if it does it prints the the whole record and goes to the "next" one.
Code:

rt=RT
I did this because RT= record terminator, so it would give me the name that matched the end of the record, not the start. So I just copy the RT to rt as i scan, and insert rt (the one from the previous record) before my printout.

I hope it makes sense enough for you to figure out.

PS:
You can add something like
Code:

ORS='-------------\n'
if it'll help you with readability of the output.
here's the output using your second sample as a source:
Code:

awk -F '\n' '/Errors/{for(i=1;i<=NF;i++){
                if ($i~/^ORA/) {
                        print rt$0;rt=RT;next}
                }}{rt=RT}' RS='(Mon|Tue|Wed|Thu|Fri|Sat|Sun)' ORS='-------------\n' 'file'
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
-------------
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
-------------

Edit: Didn't realize that the line immediately after Error starts with ORA. Anyways, here's a non 2am 1/2 asleep version
Code:

awk -F'\n' '{for (i=1;i<=NF;i++)
    if ($i~/^Error/&&$(i+1)~/^ORA/) {print rt$0;break}}
    {rt=RT}' RS='(Mon|Tue|Wed|Thu|Fri|Sat|Sun)' 'file'


jschiwal 10-04-2007 02:00 AM

[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.
' junk | sed -rn '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/,/^$/{        # Selects a single section at a time.  Inside a bracket, you can have pattern tests for lines in between.
                                                      /^$/!H  # If this isn't a blank line (end of the range), then add this line to the Hold buffer.
                                                    /^$/{      # At the end of the pattern, so check if the patter 'ORA' exists.  If so, yank back the Hold buffer and print it out.
                                                          x    # exchange the current working buffer (blank) with the Hold buffer.  This both recalls the lines from the hold buffer and clears the hold buffer.
                                                          /ORA/p  # print out the lines.
                                                        }
                                                    }'

I don't see any lines in the sample set that contain an error.
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
$ sed -r '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/i\
' junk | sed -rn '/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/,/^$/{
                                                      /^$/!H
                                                      /^$/{
                                                          x
                                                          /Error.*\nORA/p
                                                          }
                                                      }'


bigearsbilly 10-04-2007 02:37 AM

this does it...

Code:

#!/usr/bin/perl


while (<ARGV>) {
    if (/Errors in file/) {
        print;
        while (<ARGV>) {
            last unless /^ORA-/;
            print;
        }
    }
}


sagarbsa 10-04-2007 04:50 AM

Thanks a lot Dudes. Now the program is working fine. But Wanted to know what does "/^$/" and "x" implies.

jschiwal 10-04-2007 06:29 AM

Quote:

Originally Posted by sagarbsa (Post 2912795)
Thanks a lot Dudes. Now the program is working fine. But Wanted to know what does "/^$/" and "x" implies.

/^$/ is the pattern that matches an empty line.
"x" exchanges the Hold buffer with pattern space. The pattern space is where lines are read into.

sagarbsa 10-08-2007 12:12 AM

Thanks JSCHIWAL. The program is done now. Can you suggest some good awk and sed tutorial.

angrybanana 10-08-2007 12:02 PM

Here's some good ones.

sed = http://sed.sf.net/sedfaq.html | http://xrl.us/sedintro#uh-0 | http://xrl.us/sedstd | http://www.gnu.org/software/sed/manual/

awk = http://www.gnu.org/software/gawk/manual/ | http://catonmat.net/download/awk.cheat.sheet.txt

sagarbsa 10-10-2007 01:46 AM

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

archtoad6 11-02-2007 09:25 AM

Probably a different ver. of "awk".

On my box (SimplyMEPIS 6.0):
Code:

$ awk --version
GNU Awk 3.1.5

I.e. my awk is actually gawk.
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.