Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extraction using awk or sed

Status
Not open for further replies.

harris2107

IS-IT--Management
Aug 18, 2007
3
US
Hi all,
I have a file (tnsnames.ora in Oracle) from which i have to extract the values of two fields. Suppose following is the content of my file called "inputfile.txt"

(ADDRESS = ( PROTOCOL = TCP ) ( HOST = 1.1 ) ( PORT = 1521 ))
(ADDRESS=(PROTOCOL=TCP)(HOST=2.1)(PORT=1521))
(ADDRESS = ( PROTOCOL = TCP ) ( HOST = 3.1 ) ( PORT = 1521 ))

I want to extract the value of HOST from this file and assin it to an array. For eg. from the above file, i need to get the HOST values and store in the array like

ip[1]=1.1
ip[2]=2.1
ip[3]=3.1

That is i want to extract just the values of HOST from all the lines in the file given. Remember the format is the same but there are spaces in the first and third row but not in the second row. Any help would be greatly appreciated.

Thank you,
Harris.
 
Hi

Well, the following will place those data into the ip [tt]awk[/tt] array :
Code:
awk -F'[ =()]+' '{for(i=1;i<NF;i++)if($i=="HOST")ip[++n]=$(i+1)}' inputfile.txt
But I do not think this will help you too much. What is your goal ?

Feherke.
 
harris2107,
the same question has been asked and answered on another forum by multiple posters with no indication by you whether you understood the solutions and/or needed further assistance.
Pls stop leaching from multiple places!

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top