|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Code:
awk -F\( '/HOST|PORT/{print $NF}' RS=\) inputfileIf wanting it in the same line Code:
awk -F\( '/HOST|PORT/{x=(x?x" & ":z) $NF}END{print x}' RS=\) inputfile |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Code:
perl -ne 'while(/((HOST|PORT) = .+?)\)/g) {print "$1\n"}' inputfile |
|
#4
|
||||
|
||||
|
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 | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|