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)