Perl script - Help me extracting a string

I have input like this :

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 07-FEB-2012 04:19:45
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/t3local_apps/apps/oracle/product/11.2.0/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = atoadb01)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = atta1)))
OK (0 msec)

I need search patterns that will search only HOST = atoadb01 & PORT = 1521

Please help me in extracting the required strings from the above inputs.

Thanks a ton :slight_smile:

awk -F\( '/HOST|PORT/{print $NF}' RS=\) inputfile

If wanting it in the same line

awk -F\( '/HOST|PORT/{x=(x?x" & ":z) $NF}END{print x}' RS=\) inputfile
perl -ne 'while(/((HOST|PORT) = .+?)\)/g) {print "$1\n"}' inputfile
$
$ perl -lne 'print "$1\n$2" if /(HOST.*)\)\((.*?)\)/' input
HOST = atoadb01
PORT = 1521
$
$ # For output on same line
$ perl -lne 'print "$1 \& $2" if /(HOST.*)\)\((.*?)\)/' input
HOST = atoadb01 & PORT = 1521
$
$

tyler_durden