UNIX Programming, Certification, System Administration, Performance Tuning Reference Books
Awk Search

1) I have a variable called service_found assign to it is "car". I have a file with multiple entries of "car" (see example). I just need to find "car" not "car1" or "car2".

service_found=car
/\service_found\ <- is this correct to just "car"

car1
car2
2car
3car
car <- i just want this entry

2)
if my syntax was right then what is wrong with this code?

awk '
/Node name/ {
node_found = ($4 == find_node ? 1 : 0);
}
/Service name/ && node_found {
service_found = ($4)
}
/\service_found/ {
print " Port listing"
print " ------------"
print " "
print "Node Name = " node_found
print "Service Name = " service_found
print "Port Number = " $2
}
' $dblist $nodelist $servicelist

/-----------------------------/
1) use (if service name in first field, if not replace $1 by the right field) :
$1 == service_found

2) Your script with corrections :

awk '
/Node name/ {
???node_found = ($4 == find_node);
}
/Service name/ && node_found {
???service_found = $4;
}
$1 == service_found {
print " Port listing"
print " ------------"
print " "
print "Node Name = " node_found
print "Service Name = " service_found
print "Port Number = " $2
}
' $dblist $nodelist $servicelist

Why three input files ?
Are all the file the same format ?
I'm not sure this script do what you want ...

/-----------------------------/
Here is my scripts. it does need three input files, each file is different.
I am having problems with the service_found.

After this step
/Service name/ && node_found {
service_found = ($4)
I need the service_found in a search / / then print..

Hope you can understand this.

!/bin/ksh

db=$1
dblist=listdb.txt
nodelist=node_directory.txt
servicelist=services.txt

awk '
/Database name/ {
db_found = ($4 == "'$db'" ? 1 : 0);
}
/Node name/ && db_found {
find_node =($4)
}
/Node name/ {
node_found = ($4 == find_node ? 1 : 0);
}
/Service name/ && node_found {
service_found = ($4)
}
/\service_found/ {
print " Port listing"
print " ------------"
print " "
print "Database name = " db_found
print "Node Name = " node_found
print "Service Name = " service_found
print "Port Number = " $2
}
' $dblist $nodelist $servicelist

/-----------------------------/
Your db test will not works (See my response to your post "Awk in a script")
Modify the pattern /\service_found/.

Please post the format of the three files.

/-----------------------------/
How the scripts work from command to the end.
1) cmd - ./nodelist IQSB
2) in frist input file- scripts searches for IQSB then find the node name
3) in second input file - searches for Node name then find the service name.
4) in last input file - searches for service name and prints out IQSB, Node name, and serivce name. I just won the service to be found not any thing that matches it..

First input file looks like
Database 1 entry:

Database alias = IQSB
Database name = IQSB
Node name = ISTSB
Database release level = 9.00
Comment =
Directory entry type = Remote
Catalog node number = -1

Second input file.

Node 13 entry:

Node name = ISTSB
Comment =
Protocol = TCPIP
Hostname = tornsist
Service name = db2isb

last input file ;

db2isb 12340/tcp
DB2_db2isb 12341/tcp
db2isbi 12344/tcp

/-----------------------------/
Try this script :

db=$1
dblist=listdb.txt
nodelist=node_directory.txt
servicelist=services.txt

awk -v find_db="$db" '
/Database name/ && find_db && $4 == find_db {
???db_found = $4;
???find_db = 0;
???find_db_node = 1;
???next;
}
/Node name/ && find_db_node {
???node_found = $4;
???find_db_node = 0;
???find_node = $4;
???next;
}
/Node name/ && find_node && $4 == find_node {
???find_node = 0;
???find_node_serv = 1;
???next;
}
/Service name/ && find_node_serv {
???service_found = $4;
???find_node_serv = 0;
???find_service = $4;
???next;
}
find_service && $1 == find_service {
???print " Port listing"
???print " ------------"
???print " "
???print "Database name = " db_found
???print "Node Name = " node_found
???print "Service Name = " service_found
???print "Port Number = " $2
???exit;
}
' $dblist $nodelist $servicelist

I think that the solution of your problem can be more simple...

/-----------------------------/
This exactly what I need.. But I have one problem. It works if for a 2 medium and 1 small input files, but I use 3 medium files it does not come out.. the out is blank... Do you have any clues why???

/-----------------------------/
More info on my input files
listdb.txt
518 lines 15689 characters

node_directory.txt
141 lines 3743 characters

services.txt
741 lines 23809 characters.

It get lost in between the listdb.txt and node_directory. The reason I know this is I cut the list down to half for both list.txt and node_directory and it works fine..

/-----------------------------/
I don't see why the size of the input files can be at the origin of your problem.

Quick Links:
Do you have a UNIX Question?

Unix Home: Unix System Administration Hints and Tips