Invoking system(cmd) inside awk command

Hi,

I was searching for a way to grep 2 lines before and after a certain keyword, and I came across the following code..

awk "\$0 ~ /ORA-/ { 
cmd=\"awk 'NR>=\" NR-2 \" && NR<=\" NR+2 \"' init.ora\"
system(cmd)
}" input_file

I could not understand how this works. What is system() ? what does that do? Can someone please help me understand what the above command does? Curious to know.

Thanks.

system(expression) executes the command given by expression and return the exit status of the command.

The awk program that you posted is looking for a pattern ORA- in the file: input_file

Once found, it is prints records between NR-2 && NR+2 from file: init.ora

NR is current input record # with pattern ORA- in the file: input_file

You can put a print statement to understand what is going on:

print cmd
system(cmd);

What would be the input file? To me, that script made sense only if input_file actually is init.ora.
Did you consider grep 's -A and -B options?