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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk script does not work with huge files 1

Status
Not open for further replies.

LotoL

Programmer
Mar 17, 2004
20
CA
Hello, I have develop a awk script to look into three files.

Here is the problem. It works if for a 2 medium and 1 small input files, but it i use 3 medium files it does not come out.. the out is blank... Do you have any clues why???

see script at the bottom

How the scripts work from command line 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 (listdb1.txt - 518 lines 15689 characters )

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.txt - 141 lines 3743 characters )

Node 13 entry:

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

last input file (services.txt - 741 lines 23809 characters)

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


Script:
#!/bin/ksh
dblist=listdb1.txt
nodelist=node.txt
servicelist=services.txt

db=$1

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 " "
print " ------------"
print " Port Listing"
print " ------------"
print " "
print "Database name = " db_found
print "Node Name = " node_found
 
[tt]
FILENAME!=oldfile { which++; oldfile=FILENAME }
!node&&/^Database name/&&$4==find_db, /Node name/{
if ($0 ~ /^Node name/ ) node = $4 }
2==which&&/^Node name/&&$4==node,/^Service name/{
if ($0 ~ /^Service name/) service=$4 }
3==which && service == $1 {
print "\n ------------"
print " Port Listing"
print " ------------\n"
print "Database name = " find_db
print "Node Name = " node
print "Service name = " service
exit }
[/tt]

If you have nawk, use it instead of awk because
on some systems awk is very old and lacks many useful features.

Let me know whether or not this helps.


 
Thanks,

But I have no clue on how to use nawk. I'm just a newbie with awk. How do I use my three input file on the the script you wrote and how do I run it.
 
In your script, replace awk by nawk
(before verify that the nawk is available on your system : [tt]which nawk[/tt])

futurelet gives you an awk script, you can use it by :
[tt]nawk -v find_db="$db" ' futurelet script ... '[/tt]

or put it in a file (find_db.awk for example) :
[tt]nawk -v find_db="$db" -f find_db.awk[/tt]


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


Jean Pierre.
 
Where do you think the problems is comming from?

I get an error when running nawk -v find_db="$db" -f find_db.awk IQSB;

Syntax Error The source line is 3.
The error context is
>>> dblist=/home/zzzzz/GetNode/listdb1. <<< txt
awk: 0602-500 Quitting The source line is 3.

#!/bin/ksh

dblist=/home/zzzzz/GetNode/listdb1.txt
nodelist=/home/zzzzz/GetNode/Node.txt
servicelist=/home/zzzzz/GetNode/services.txt

(dblist,nodelist,servicelist) in FILENAME

FILENAME!=oldfile { which++; oldfile=FILENAME }

!node&&/^Database name/&&$4==find_db, /Node name/{
if ($0 ~ /^Node name/ ) node = $4 }

2==which&&/^Node name/&&$4==node,/^Service name/{
if ($0 ~ /^Service name/) service=$4 }

3==which && service == $1 {
print "\n ------------"
print " Port Listing"
print " ------------\n"
print "Database name = " find_db
print "Node Name = " node
print "Service name = " service
exit }
 
#!/bin/ksh

dblist=/home/zzzzz/GetNode/listdb1.txt
nodelist=/home/zzzzz/GetNode/Node.txt
servicelist=/home/zzzzz/GetNode/services.txt

(dblist,nodelist,servicelist) in FILENAME

Why such lines in an awk script ?
Are you confused determining what should be in a shell script and what should be in an awk program ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
The awk script starts at FILENAME!=....
The previous lines must be in your shell script :

Code:
#!/bin/ksh
# find_db.ksh

db=${1:?'Missing database name as argument 1'}

dblist=/home/zzzzz/GetNode/listdb1.txt
nodelist=/home/zzzzz/GetNode/Node.txt
servicelist=/home/zzzzz/GetNode/services.txt

nawk -v find_db="$db" -f find_db.awk $dblist $nodelist $servicelist

Code:
# find_db.awk
FILENAME!=oldfile { which++; oldfile=FILENAME }

!node&&/^Database name/&&$4==find_db, /Node name/{
   if ($0 ~ /^Node name/ ) node = $4 }

 2==which&&/^Node name/&&$4==node,/^Service name/{
   if ($0 ~ /^Service name/) service=$4 }

 3==which && service == $1 {
   print "\n ------------"
   print " Port Listing"
   print " ------------\n"
   print "Database name = " find_db
   print "Node Name     = " node
   print "Service name  = " service
   exit }

I heve tested the awk script, works fine.
Good work futurelet

Jean Pierre.
 
Are you telling me that shell script and awk can not be together in one combine script?
 
Re-read your original script.
Your ksh script execute awk witch execute is own script ...

Jean Pierre.
 
Excellent Work Guys,

Thanks aigles(Jean) and futurelet.

but Im still having problems with huge files :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top