Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-07-2012
Registered User
 

Join Date: Sep 2011
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
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
Sponsored Links
    #2  
Old 02-07-2012
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 

Join Date: Oct 2010
Location: France
Posts: 2,529
Thanks: 64
Thanked 521 Times in 500 Posts

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

If wanting it in the same line

Code:
awk -F\( '/HOST|PORT/{x=(x?x" & ":z) $NF}END{print x}' RS=\) inputfile

Sponsored Links
    #3  
Old 02-07-2012
balajesuri's Avatar
#! /bin/bash
 

Join Date: Apr 2009
Location: India
Posts: 1,019
Thanks: 9
Thanked 285 Times in 277 Posts

Code:
perl -ne 'while(/((HOST|PORT) = .+?)\)/g) {print "$1\n"}' inputfile

    #4  
Old 02-07-2012
durden_tyler's Avatar
Registered User
 

Join Date: Apr 2009
Posts: 1,684
Thanks: 4
Thanked 209 Times in 189 Posts

Code:
$
$ 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
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Displaying exponent value as string in PERL script sbasetty Shell Programming and Scripting 3 10-06-2011 02:43 PM
Perl script: extracting numbers from a date formatt vas28r13 Shell Programming and Scripting 1 08-08-2011 10:44 AM
Perl: Extracting a char from a string. KenJackson Shell Programming and Scripting 7 08-03-2010 05:31 PM
perl script to list filenames that do not contain given string royalibrahim Shell Programming and Scripting 21 04-22-2008 01:55 PM
Extracting a string from one file and searching the same string in other files mohancrr Shell Programming and Scripting 1 09-19-2007 03:17 AM



All times are GMT -4. The time now is 04:36 AM.