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

Problem with pattern match in function 1

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I have the following function
function get_tblspace_size(name) {
#
print name
tblsp = 0
while ( ( getline < "/tmp/owspace.lst" ) > 0 ) {
if ($0~/name/) {
getline
print $0
tblsp = tblsp + $0
}
}

close("/tmp/owspace.lst")
return tblsp/1024

}

but is does not work.

The file /tmp/owspace.lst contains some data like

/data/tutu/titi/TT_TRINIDAD123456.dbs
123 560
/data/tutu/titi/TT_TRINIDAD345663.dbs
50 300
/data/tutu/titi/TT_TOBAGO
234 1099

What I want to do is find the line that matches TT_TRINIDAD and add the values of the first columns of the match

the match works fine outside the function if I do
nawk '{if ($0~/TT_TRINIDAD/) {print $0}}' < /tmp/owspace.lst

but it does not if I do get_tblspace_size{TT_TRINDAD}

Thanks for your help!

_________________________
 
Instead this;
if ($0~/name/) {
Try this:
if ($0~name) {
Variables are not handled the same way as litterals.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks PHV, this now works however I have two problems now:

1) when a match with "name" is found awk won't go any further the programs hangs if I leave the "getline" in the function. If I remove it then it is OK. Howver when a match is found I want to read the next line, maybe I should not use getline?

2) $0~name matches more than I want. For instance if name =TT_TRINIDAD it matches

/data/tutu/titi/TT_TRINIDAD123456.dbs
and
/data/tutu/titi/TT_TRINIDAD123678.dbs which is OK but it also matches
/data/tutu/titi/TT_TRINIDAD_TOTO123456.dbs and that I don't want

Thanks!
 
1) Do a getline with the same input file !
getline < "/tmp/owspace.lst"
2) You may try something like this:
$0~name"[0-9]" or $0~name"[^_]"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
this worked like a treat thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top