Get value between brackets

Hi
I am having hard time getting this right and need some help. I Have several log files, and everyone contains the following 3 lines at the end:

4 ETW000 Disconnected from database.
4 ETW000 End of Transport (0000).
4 ETW000 date&time: 13.01.2011 - 08:03:28

I need to capture the value between brackets to be able to compare it to another one and make a decision. In this case, it is 0000.

Could someone help pls.

$
$
$ cat f2
4 ETW000 Disconnected from database.
4 ETW000 End of Transport (0000).
4 ETW000 date&time: 13.01.2011 - 08:03:28
$
$
$ perl -lne 'print $1 if /^.*End of Transport \((.*)\)\.$/' f2
0000
$
$

tyler_durden

 sed -n 's/.*[(]\([0-9]*\)[)].*/\1/p' < infile
tail -2 infile  | grep -oP '(?<=\()[[:digit:]]+(?=\))' 

Assumes last line never has a pattern like "(nnnnnn)", where n are some number of digits. Pattern matches one or more (+) digits between parentheses but not the parentheses themselves (-P switch enables the use of Perl look-behind/look-ahead).

If the second to the last line is really fixed to be
4 ETW000 End of Transport (0000)
where only the number inside the () varies, and this line never occurs elsewhere in the files, then you could simplify and use:

grep -oP '(?<=4 ETW000 End of Transport \()[[:digit:]]+(?=\))'  infile
perl -e 'while(<STDIN>) { print $1 if(/\((\d+)\)/); }' < infile

use -n and why the redirection?

perl -ne 'print $1 if .... ' file

---------- Post updated at 07:14 PM ---------- Previous update was at 07:10 PM ----------

tail -4 file| awk -F"[()]" 'NF&&/\(/{print $(NF-1)}'
awk  -F "[)(]"  'NR==FNR {t=NR;next} FNR==t-1 {print $2}' infile infile

Thank you soooooooooo much for all your help. This is great.