The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Number of lines in a file (perl script) jisha Shell Programming and Scripting 5 05-20-2008 08:11 AM
Script to Scan proclog files deeprajn95 Shell Programming and Scripting 3 05-12-2008 07:25 AM
Perl: Getting back reference from s modifier cooldude Shell Programming and Scripting 8 03-19-2008 09:49 AM
Perl script to scan through files gholdbhurg Shell Programming and Scripting 1 03-05-2008 10:53 PM
How to scan only new lines added in file? redlotus72 UNIX for Dummies Questions & Answers 3 04-28-2005 04:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
gholdbhurg gholdbhurg is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 26
Perl script to scan back lines

Hi Perl gurus,
I have this file to scan through. Sample lines below:

2008031A, USERNAME, 12345, give ABC, take XYZ, transaction submitted
2008031B, USERNAME, 12346, waiting for processing
2008031C, USERNAME, 12347, Retrieving response
2008031D, USERNAME, 12348, This is not a valid dealing
2008031E, USERNAME, 12349, State has failed
2008031F, USERNAME, 12350, System=0
2008031G, USERNAME, 12351, Waiting for new txns
2008031H, SOMEONE, 12352, give STE, take GVO, transaction submitted
2008031I, SOMEONE, 12353, waiting for processing
2008031J, SOMEONE, 12354, Retrieving response
2008031K, SOMEONE, 12355, This is not a valid dealing
2008031L, SOMEONE, 12356, State has failed
2008031M, SOMEONE, 12357, System=0
2008031N, SOMEONE, 12358, Waiting for new txns

I need to search for this pattern
-->
"This is not a valid dealing"
When one line found a match, it should write in the log the <UserName> as well as the give and take value (i.e. ABC, XYZ)

After scanning above file, error log should appear:
ERROR: USERNAME (ABC, XYZ)
ERROR: SOMEONE (STE, GVO)

Any ideas?

Thanks in advance guys.
  #2 (permalink)  
Old 03-18-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Can transactions be intermingled in the log file, or will all details of a transaction be on adjacent lines, and all adjacent lines belong to the same transaction, or mark the boundary to the next transaction?

Does a transaction always start with the "give" and "take" stuff? Does a transaction always end with the "Waiting for new txns" line?


Code:
vnix$ perl -ne 'if (/give ([^,]*), take ([^,]*), transaction submitted/) { $give = $1; $take = $2; }
    if (/Waiting for new txns/) { $give = $take = undef; }
    if (/, ([^,]*), [^,]*, This is not a valid/) { print "UPPERCASE: $1 ($give, $take)\n"}' /tmp/txn 
UPPERCASE: USERNAME (ABC, XYZ)
UPPERCASE: SOMEONE (STE, GVO)

I guess all the uppercase is an indication that this is the FINANCIAL SECTOR we are dealing with here ...?
  #3 (permalink)  
Old 03-18-2008
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,797
consider and awk version:

Code:
csadev:/home/jmcnama> cat t.awk   
awk -F, 'BEGIN { give=""}
         {
            if($4 ~ /give/){
                  give=sprintf("%s%,%s" ,
                        substr($4, length($4)-3),
                        substr($5, length($5)-3 ) )
                  }
            if($4 ~ /This is not a valid dealing/) {
                printf("ERROR: %s (%s)\n", $2, give)
                }
         } ' filename

csadev:/home/jmcnama> cat filename
2008031A, USERNAME, 12345, give ABC, take XYZ, transaction submitted
2008031B, USERNAME, 12346, waiting for processing
2008031C, USERNAME, 12347, Retrieving response
2008031D, USERNAME, 12348, This is not a valid dealing
2008031E, USERNAME, 12349, State has failed
2008031F, USERNAME, 12350, System=0
2008031G, USERNAME, 12351, Waiting for new txns
2008031H, SOMEONE, 12352, give STE, take GVO, transaction submitted
2008031I, SOMEONE, 12353, waiting for processing
2008031J, SOMEONE, 12354, Retrieving response
2008031K, SOMEONE, 12355, This is not a valid dealing
2008031L, SOMEONE, 12356, State has failed
2008031M, SOMEONE, 12357, System=0
2008031N, SOMEONE, 12358, Waiting for new txns

csadev:/home/jmcnama> t.awk
ERROR:  USERNAME ( ABC, XYZ)
ERROR:  SOMEONE ( STE, GVO)

  #4 (permalink)  
Old 03-18-2008
gholdbhurg gholdbhurg is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 26
Hi era/jim,
Thanks for the quick response.

>>>
Hi era,
My responses below:
1. Can transactions be intermingled in the log file, or will all details of a transaction be on adjacent lines, and all adjacent lines belong to the same transaction, or mark the boundary to the next transaction?
ANS:
Yes, all details of a transaction will be on adjacent lines, and all adjacent lines belong to the same user/transaction.

2. Does a transaction always start with the "give" and "take" stuff? Does a transaction always end with the "Waiting for new txns" line?
ANS:
Yes that will always be the start line of all txns, but the end lines may vary.
For successful ones, there wont be any "This is not a valid dealing" line in between.
>>>

Btw if possible, i would prefer this in perl

Hope to hear from the other gurus.
Appreciate it very much.

Last edited by gholdbhurg; 03-18-2008 at 12:41 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0