![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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 ...? |
|
||||
|
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)
|
|
||||
|
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.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|