CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Regex search

 



doni
New User

Aug 27, 2015, 10:06 AM

Post #1 of 7 (1441 views)
Regex search Can't Post

Hello
I need some help for a Perl code.
I have a logfile which I parse with perl line by line searching for ORA errors i .e. ORA-28000: , ORA-04063: etc
Say we have this in the logfile:


16:34:45: 16:34:45 SQL> begin pk_system_deploy_meta.upgrade_resource('MA_V_CCAR_DLY_BAL_POSN', TRUE); end;
16:34:45: 16:34:45 2 /
16:34:45: begin pk_system_deploy_meta.upgrade_resource('MA_V_CCAR_DLY_BAL_POSN', TRUE); end;
16:34:45: *
16:34:45: ERROR at line 1:
16:34:45: ORA-20001: ORA-20001: ^M
16:34:45: artos_ma CREATE OR REPLACE FORCE VIEW v_ccar_dly_bal_posn
16:34:45: AS
16:34:45: SELECT
16:34:45: dly_bal_posn.adjmt_id AS adjmt_id
16:34:45: , dly_bal_posn.adjmt_oprn_typ AS adjmt_oprn_typ
16:34:45: , dly_bal_posn.ati AS ati
16:34:45: , ^M
16:34:45: ORA-24344: success with compilation error^M
16:34:45: ORA-06512: at "ARTOS_PROC.PK_SYSTEM_DEPLOY_META", line 3297
16:34:45: ORA-06512: at "ARTOS_PROC.PK_SYSTEM_DEPLOY_META", line 3447
16:34:45: ORA-06512: at line 1

So my search will match first "ORA-20001: ORA-20001:"
and I will have line "16:34:45: ORA-20001: ORA-20001: ^M " in variable
SO I would like to get the failed file (MA_V_CCAR_DLY_BAL_POSN) assosiated with this error ORA-20001: ORA-20001:
I am thinking of going backwards from matched line until beggining of logfile searching for first regex match -for example upper case letters inside ()
Do you have any idea how this can be achieved?


BillKSmith
Veteran

Aug 27, 2015, 12:40 PM

Post #2 of 7 (1432 views)
Re: [doni] Regex search [In reply to] Can't Post

It speed and memory are not a problem, an easy solution is to read the entire log file into an array and reverse the array. Look for the ORA just like you do now. Then look for the next error line.
Good Luck,
Bill


FishMonger
Veteran / Moderator

Aug 27, 2015, 1:27 PM

Post #3 of 7 (1428 views)
Re: [BillKSmith] Regex search [In reply to] Can't Post

Or, use the File::ReadBackwards module.
http://search.cpan.org/~uri/File-ReadBackwards-1.05/ReadBackwards.pm


doni
New User

Aug 28, 2015, 1:08 AM

Post #4 of 7 (1396 views)
Re: [FishMonger] Regex search [In reply to] Can't Post

Yes I was intending to use that backward package. But can't figure out how to print the file until the matched line and search for "(UPPER LETTERS)"


FishMonger
Veteran / Moderator

Aug 28, 2015, 6:16 AM

Post #5 of 7 (1371 views)
Re: [doni] Regex search [In reply to] Can't Post

Are you saying you don't know how to loop over an array, or that you don't know how to use a regex?

What have you tried?

What errors/warnings are you receiving?


doni
New User

Aug 28, 2015, 6:32 AM

Post #6 of 7 (1366 views)
Re: [FishMonger] Regex search [In reply to] Can't Post

First I am not sure it is a good idea to fill an array - we are talking about 200MB of text file - I am thinking about reversing the logfile from matched line back to the beggining of logfile and searching for first () and upper case letters
I suppose hardest part for me will be the regex - how to search for (UPPER CASE)


FishMonger
Veteran / Moderator

Aug 28, 2015, 6:43 AM

Post #7 of 7 (1362 views)
Re: [doni] Regex search [In reply to] Can't Post

I normally put in a lot of effort in helping others solve their coding issues as long as I see that they have put in a reasonable effort themselves. So far I'm not seeing that effort on your part.

What have you tried?

What errors/warnings are you receiving?

Please post your code.

These links will help in learning how to use a regex to match UPPER CASE characters.
http://perldoc.perl.org/perlre.html
http://perldoc.perl.org/perlreref.html

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives