Extract a string from a file

I have a file with below contents.

INCLUDE
INCLUDE SYSLIB(SANJ)
INCLUDE SYSLIB(BIS)
NAME BQTFL(R)
dfdg fgbb NAME B

i want to grep for "INCLUDE SYSLIB" in the file and do some operation so that my output will be in the bracketed value as below.

SANJ
BIS

Pls let me know how can i achieve this.

try

awk -F "[()]" '/INCLUDE SYSLIB/{print $2}' file
awk -F"(" '{print $2}' file | awk -F")" '{print $1}'
 
awk -F"(" '{print $2}' file | sed 's/)//g'

This would work only if the content of the file is as below

SYSLIB(SANJ)
INCLUDE SYSLIB(BIS)

i am not sure in which field that string will be present..so i cannt use

cut  or awk print $2
#!/usr/bin/perl -w

while(<>) {
if ($_ =~ /INCLUDE SYSLIB/) {
print "$1\n" if /\((.*)\)/;
}
}

Run as :

perl try.pl input

Got output for given sample input:

SANJ
BIS

pamu solution works as a one-liner.

In sed:

sed '/INCLUDE SYSLIB/s/^.*(\(.*\))$/\1/' input

gives the following output for given input :

INCLUDE
SANJ
BIS
NAME BQTFL(R)
dfdg fgbb NAME B

I think regex can be optimized :wink:

provide more input sample for further help

sed -rn '/INCLUDE SYSLIB/ s/^[^(]*\(|\)[^)]*$//gp' file
SANJ
BIS

You may try awk

$ cat <<eof | awk '/INCLUDE SYSLIB/{gsub(/.*\(|\).*$/,x);print}'
INCLUDE
INCLUDE SYSLIB(SANJ)
INCLUDE SYSLIB(BIS)
NAME BQTFL(R)
dfdg fgbb NAME B
eof

SANJ
BIS

for file use this

$ awk '/INCLUDE SYSLIB/{gsub(/.*\(|\).*$/,x);print}' file