Explain this AWK script plz

Hi frnds,

one my frnds has given resolution for my problem as below. it working great , but i couldnt understand somethings in the script.
Why ++ operator after the function calling. how these each block working. will each run for each input line sequencially or one block for all the lines and next block execeted? plz clarify.

The script is

 
# ora.sh
 
awk -v Outfile=ora.txt '
/^ORA-/ {
split($0, f, "\"");
Target_schema = f[2];
Target_table = f[4];
Ora_error = $0;
}
 
/Targ Rowid=/ { 
Rejected_count++ ;
Get_detail++;
printf "#%d => %s\n", Rejected_count, Ora_error;
next;
}
 
/^)/ && Get_detail {
print Rejected_count,Values_detail > Outfile;
Values_detail = "";
Get_detail = 0;
next;
}
 
Get_detail {
sub(/\(.*\):/,"=");
Values_detail = Values_detail $0 "|"
}
 
END {
print "Total Lines in Session Log",FILENAME,"is :",NR;
print "Total Nr of Rejected Records Captured in Sesslog is :",Rejected_count;
} 
' ora.log

[/SIZE][/FONT][/SIZE][/FONT]

So, what is the problem u have to resolve ??? It's better to know the requirements (input/output) and the solution than just the solution, right ?
plz clarify :slight_smile:

[Code
Hi thanhdat
Plz look into my actual posting and plz explan me the AWK script that one of our frnd given as a solution.Plzzz

Script Performance problem . urgent frnds - The UNIX and Linux Forums

PLzz

[/Code]

awk -v Outfile=ora.txt '
. . .
' ora.log

Execute awk script for the input file ora.log.
The variable Outfile is initialized, before executing the awk script, with the output file name

/^ORA-/ {
   split($0, f, "\"");
   Target_schema = f[2];
   Target_table = f[4];
   Ora_error = $0;
}

Records starting with 'ORA-' are selected..
The Oracle error text is memorized in the variable Ora_error

/Targ Rowid=/ { 
   Rejected_count++ ;
   Get_detail++;
   printf "#%d => %s\n", Rejected_count, Ora_error;
   next;
}

Records containing 'Targ RowId=' are selected.
The number of rejected records found is incremented (variable Rejected_count).
The following records will contain the columns details ending with the ')' record.
The variable Get_detail, which is set to TRUE (value 1),indicates that we are now reading for columns details.

/^)/ && Get_detail {
   print Rejected_count,Values_detail > Outfile; 
   Values_detail = "";
   Get_detail = 0;
   next;
}

Records starting with ')'' are selected if we are reading columns details.
There is no more columns details records for this rejected record, so the memorized values of columns are writen in the output file.
The variable Get_detailis set to FALSE (value 1),

Get_detail {
   sub(/\(.*\):/,"=");
   Values_detail = Values_detail $0 "|"
}

Records are selected if we are reading columns details.
The value of the column is memorized in the[/i] Values_detail[/i] variable.

END {
   print "Total Lines in Session Log",FILENAME,"is :",NR;
   print "Total Nr of Rejected Records Captured in Sesslog is :",Rejected_count;
}

Display statistics at end of file.

My apologies for my poor English.
Jean-Pierre.

Hi Thanks for you reply
but tell me what you mean by "column details"?

Means values of columns

SMA_FEED_RECEIVED_ID (SMA_FEED_RECEIVED_ID:UniChar.40:): "MASTER_MATERIAL_ATTR_222222"
SMA_SOURCE_SYSTEM_INSTANCE (SMA_SOURCE_SYSTEM_INSTANCE:UniChar.40:): "BRE0222202"
SMA_MATERIAL (SMA_MATERIAL:UniChar.18:): "2222B"
SMA_OBJVERS (SMA_OBJVERS:UniChar.1:): "2222A"
SMA_CHANGED (SMA_CHANGED:UniChar.1:): ""
SMA_DIVISION (SMA_DIVISION:UniChar.2:): "02221"
SMA_MATL_GROUP (SMA_MATL_GROUP:UniChar.9:): "2227131"
SMA_MATL_TYPE (SMA_MATL_TYPE:UniChar.4:): "ZSTK"

Jean-Pierre.

 
Hi frnd,
 
My main problem is that
 
We need to identify the keyword Targ Rowid=  and �)� . Then we need to read the block of data (column values ) resides between those search pattern. Ok.
 
And we hav to loop through the entire log file to pick all required column values. Fine
 
Now in ur script, you have onse function named �Get_detail� which replace unwanted data with = symbol and make the block of data into single line with | delimited. Fine
 
When ur calling the function , y hv you mention ++ symbol. (ie., Get_detail++) . whether it is calling the function or just a normal variable declaration. If its declaration whats the use of it. 
What is the use of next; how its helping us to fulfill our requirement here.?
 
In the 3rd , we have like  /^)/ && Get_detail { . whats the use of Get_detail here. Is it a function calling? If so how its working. And why get_detail=0;
 
 
my main question is that,
 
we want to identify the both seach pattern and get the block of data and the block of data with pipe delimited. And need to loop through the entire log file.
 
You hv achived it in ur script. That is great. But I want understand how it capture the block of data .how this script loop through the session log for same purpose.
 
Plz explin the control flow in the script( ie., when ,which line ll get executed ?) explain me line by line. Plz frnd plzz .. even I couldn't sleep well since I couldn't understand the script.
 
Note: plz don't give overview explaination of the scriopt as you gave earlier. Plz little pit deeper. Line by line I want . I want control flow in the script.Plz dont ignor this post.
 
 
Send me the explination to my mail id:   gopal.narayanan@tcs.com
 

The minimum to understand an awk script (Extract from awk man pages) :

The following code :

/Targ Rowid=/ { 
   Rejected_count++ ;
   Get_detail++;
   printf "#%d => %s\n", Rejected_count, Ora_error;
   next;      # Proceeds with the next
input record.

}

/^)/ && Get_detail {
   print Rejected_count,Values_detail > Outfile; 
   Values_detail = "";
   Get_detail = 0;
   next;
}

Get_detail {
   sub(/\(.*\):/,"=");
   Values_detail = Values_detail $0 "|"
}

Can be rewritten like that :

$0 ~ /Targ Rowid=/ { 
   Rejected_count = Rejected_count + 1 ;
   Get_detail     = 1;
   printf "#%d => %s\n", Rejected_count, Ora_error;
   next;
}

if $0 /^)/ && Get_detail != 0 {
   print Rejected_count,Values_detail > Outfile; 
   Values_detail = "";
   Get_detail = 0;
   next;
}

Get_detail != 0 {
   sub(/\(.*\):/,"=");
   Values_detail = Values_detail $0 "|"
}

Get_detail isn't a function, it's a variable used as a boolean (0=false, other values=true).

Jean-Pierre.

i assure u , i ll sleep tonight well. i got cleared with control flow of the script. : ) Thanks you very much for explained me line by line. really thanku

[code]
Open for Open for
File Records Read Write
--------------- ------- -------- --------
Inputfile ? 5004
ora_occ.txt 5000 5000
targ_occ.txt 5000 5000
bracket_occ.txt 5000 5000
ora_error_deatail 1 5000 5000
data_block.txt 46 5000 5000
--------------- ------- -------- --------
Total 30004 10000
---------

[code]

how could get this detail. is theere any command to get details of I/O for paricular file. Plz suggest me frnd

There is no command to get this kind of detail.
This detail is the result of my analyse of your script.

Jean-Pierre.