Need help in retrieving log from a UNIX file using the search patterns

Hi everyone,

I am trying to retrieve certain log from a big file. The log size can be from 200 - 600 lines. I have 3 search patterns, out of which 2 (first and last lines) search patterns are common for all the transactions but 3rd search pattern (occurs in the middle of transaction) is unique.

Now, using these three search patterns, I want to retreive the complete transaction log (start to end) into a seperate file.

I think, this can be done using awk. I know the basic awk commands but not comfortable with the awk programming.

Can anyone help me on this? Thanks in advance.

Problem is not much clear. Please post a sample input, show all three patterns and expected output.

Thanks Anurag for the quick response. Unfortunately I can't post sample input but here is the scenario

Starting line (for tx - 1)
Transaction ID (Unique for each transaction)
End line (for tx -1)
starting line (for tx -2)
Transaction ID
End line (for tx -2)
.....
.....
starting line (for tx -10)
Transaction ID
End line (for tx -10)

The start/end lines are common for all the transactions. The transaction ID is present as part of the line in the middle of the respective transaction log.

Now, I have to write a script so that it can pull the requested transaction log (from starting line to end line) by searching the transaction ID from the log into a seperate file.

"by searching the transaction ID" ??
How you need to search log for a transaction ID.
Do you need log for only one transaction ID while one run? OR more.
Say if you want to seach for transaction ID 100 and 200, then Do you want following output:

starting line (for tx -2)
100
End line (for tx -2)
starting line (for tx -3)
200 
End line (for tx -3)

Please explain completely. You told only input file format. But not explained how do you plan to pass transaction ID you need to search.

One way of tacking this task. First find the line number of the match on "Transaction ID" then pass through the original file looking for the lines before, equal, and after the the match.

mylogfilename="/path/mybiglogfilename"

TAB="`echo \0011`"      # Tab character
mytransaction_id="000000000000000"
cat -n "${mylogfilename}" | grep "${mytransaction_id}" | awk '{print $1,$2}'| while read mylineno mydata
do
      mylineno_before=`expr ${mylineno} - 1`
      mylineno_after=`expr ${mylineno} + 1`
      sed -n "${mylineno_before},${mylineno_after} p" ${mylogfilename}
done

Thanks Methyl. I will try this solution and get back to you guyz as soon as I am done.