Sponsored Content
Top Forums Shell Programming and Scripting How to extract only relevant part from a sentence? Post 302961269 by Don Cragun on Thursday 26th of November 2015 05:09:29 AM
Old 11-26-2015
When I tried RavinderSingh13's sed suggestion with the supplied sample input, I got the output:
Code:
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbs.ads.com =1521))(CONNECT_DATA=(SID=vug)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=captain.adsoe.com =1521))(CONNECT_DATA=(SID=x10)))
(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 11.69.21.37  = 1521)))(CONNECT_DATA = (SERVICE_NAME = o901.ads.com)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ap60.as.com =1521))

His suggestion might work with GNU sed, but it doesn't work with the sed on OS X. You might want to try:
Code:
sed 's/.*HOST *= *\([.[:alnum:]]*\).*PORT *= *\([[:digit:]]*\).*/\1 \2/' file

which, with a standard sed produces the output:
Code:
dbs.ads.com 1521
captain.adsoe.com 1521
11.69.21.37 1521
ap60.as.com 1521

With a GNU sed, the following should work:
Code:
sed --posix 's/.*HOST *= *\([.[:alnum:]]*\).*PORT *= *\([[:digit:]]*\).*/\1 \2/' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract the relevant data files for a quarter

CTB_KT_OllyotLvos_20081204_164352_200811.txt CTB_KT_LN_utahfwd_20081204_164352_200811.txt CTB_KT_LN_utahfwd_Summ_20081204_164352_200811.txt CTB_KT_PML_astdt_prFr_20081204_210153_200811.txt CTB_KT_PML_astdt_prOt_20081204_210153_200811.txt CTB_KT_PML_astdt_Nopr_20081204_210153_200811.txt... (7 Replies)
Discussion started by: w020637
7 Replies

2. UNIX for Dummies Questions & Answers

Script to ask for a sentence and then count number of spaces in the sentence

Hi People, I need some Help to write a unix script that asks for a sentence to be typed out then with the sentence. Counts the number of spaces within the sentence and then echo's out "The Number Of Spaces In The Sentence is 4" as a example Thanks Danielle (12 Replies)
Discussion started by: charlie101208
12 Replies

3. Shell Programming and Scripting

Trim the sentence containing colon and period to extract a word in between

Hello All , i am a newbie in korn shell scripting trying to trim a sentence that is parsed into a variable . The format of the sentence has three words that are separated from other by a " : " colon and "." period . Format of the sentence looks like ... (5 Replies)
Discussion started by: venu
5 Replies

4. Shell Programming and Scripting

extract from a long sentence

Hi, There's a long sentence from which I need to extract only the part which is at the right side of the word LENGTH i.e. 15 long sentence : <INPUT VAR1 ="" DATATYPE ="number(p,s)" VAR2 ="" VAR3 ="3" VAR4="0" VAR5 ="ELEMITEM" VAR6 ="NO" VAR7 ="NOT A KEY" VAR8 ="17" LEVEL ="0" NAME... (3 Replies)
Discussion started by: dips_ag
3 Replies

5. Shell Programming and Scripting

extract a field from a long sentence!

Hi, I want to extract the value of LENGTH column (high-lighted in red) from a file which will have several lines as shown below: <INPUT VAR1 ="" DATATYPE ="number(p,s)" VAR2 ="" VAR3 ="3" VAR4="0" VAR5 ="ELEMITEM" VAR6 ="NO" VAR7 ="NOT A KEY" VAR8 ="17" LEVEL ="0" NAME ="UNIX" NULLABLE... (4 Replies)
Discussion started by: dips_ag
4 Replies

6. Shell Programming and Scripting

Extract a word from sentence

$SET_PARAMS='-param Run_Type_Parm=Month -param Portfolio_Parm="997" -param From_Date_Parm="2011-08-09"' Want to extract the value of "Portfolio_Parm" from $SET_PARAMS i.e in the above case "997" & assigned to new variable. The existence order of "Portfolio"Parm" can change, but the name... (2 Replies)
Discussion started by: SujeethP
2 Replies

7. Shell Programming and Scripting

Replacing part of the sentence using echo and sed

Hi, Iam using ksh and trying to execute the following syntax to replace one word of the sentence with a new word. But somehow sed is not able to replace the old value with new value. Please let me know where Iam going wrong. Sample Code : --> export line="VORTEX,abcdef" export... (3 Replies)
Discussion started by: ajithab
3 Replies

8. Shell Programming and Scripting

Extract part of file

Hello All, I need to extract part of a file into a new file My file is Define schema xxxxxx Insert into table ( a ,b ,c ,d ) values ( 1, 2, 3, (15 Replies)
Discussion started by: nnani
15 Replies

9. UNIX for Advanced & Expert Users

Need help to extract part of the string

Hi, I have a string with name as 20140412-s1-Potopolive_promos_20140412. So I want to extract only Potopolive string. Could you please help me the command. O/p : Potopolive Thx in advance (5 Replies)
Discussion started by: lkeswar
5 Replies

10. Shell Programming and Scripting

Extract sentence and its details from a text file based on another file of sentences

Hi I have two text files. The first file is TEXTFILEONE.txt as given below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (7 Replies)
Discussion started by: my_Perl
7 Replies
CURLOPT_RESOLVE(3)					     curl_easy_setopt options						CURLOPT_RESOLVE(3)

NAME
CURLOPT_RESOLVE - provide custom host name to IP address resolves SYNOPSIS
#include <curl/curl.h> CURLcode curl_easy_setopt(CURL *handle, CURLOPT_RESOLVE, struct curl_slist *hosts); DESCRIPTION
Pass a pointer to a linked list of strings with host name resolve information to use for requests with this handle. The linked list should be a fully valid list of struct curl_slist structs properly filled in. Use curl_slist_append(3) to create the list and curl_slist_free_all(3) to clean up an entire list. Each single name resolve string should be written using the format HOST:PORT:ADDRESS where HOST is the name libcurl will try to resolve, PORT is the port number of the service where libcurl wants to connect to the HOST and ADDRESS is the numerical IP address. If libcurl is built to support IPv6, ADDRESS can of course be either IPv4 or IPv6 style addressing. This option effectively pre-populates the DNS cache with entries for the host+port pair so redirects and everything that operations against the HOST+PORT will instead use your provided ADDRESS. Addresses set with CURLOPT_RESOLVE(3) will not time-out from the DNS cache like ordi- nary entries. The provided ADDRESS set by this option will be used even if CURLOPT_IPRESOLVE(3) is set to make libcurl use another IP version. Remove names from the DNS cache again, to stop providing these fake resolves, by including a string in the linked list that uses the format "-HOST:PORT". The host name must be prefixed with a dash, and the host name and port number must exactly match what was already added pre- viously. DEFAULT
NULL PROTOCOLS
All EXAMPLE
CURL *curl; struct curl_slist *host = NULL; host = curl_slist_append(NULL, "example.com:80:127.0.0.1"); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_RESOLVE, host); curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); } curl_slist_free_all(host); AVAILABILITY
Added in 7.21.3. Removal support added in 7.42.0. RETURN VALUE
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. SEE ALSO
CURLOPT_IPRESOLVE(3), CURLOPT_DNS_CACHE_TIMEOUT(3), CURLOPT_CONNECT_TO(3), libcurl 7.54.0 May 17, 2016 CURLOPT_RESOLVE(3)
All times are GMT -4. The time now is 06:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy