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!

matching string 2

Status
Not open for further replies.
Apr 13, 2004
316
US
To get the match for "Resource ID:" in the text below, I am using this code:

*********************************************
/^ Resource Variable Name:/ {
if ( index( $0, sought ) )
{ getline s
print s
}
}
**********************************************
but it isn't returning anything. In the text itself it appears to be a tab, but if I use a tab in the code or the exact number of spaces, it doesn't return anything.

Any help is appreciated. Thanks!

Text:
***********************************************
Example expression:

To be notified each time the average number of of processes on the
run queue on node 7 has increased by 50% or more between observations,
one could register for the event that follows:

Resource varible: IBM.PSSP.aixos.Proc.runque
Resource ID: NodeNum=7
Expression: (X - X@P) >= (X@P * .5)

 
To write a single tab, do this
[tt]/^\tResource Variable Name:/ {[/tt]

If you want to just skip any white space, no matter what combination of spaces and tabs, then
[tt]/^[\t ]+Resource Variable Name:/ {[/tt]

Your example is "Resource Variable:", not "Resource Variable Name:"

--
 
based on your (mis-spelled) sample file (for example):

nawk -v sought=IBM -f loose.awk sampleFile.txt

Code:
/Resource varible/ {
    if ( match($0, sought) ) {
      getline;
      print
    }
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks, both worked perfectly. You both also noted something that I didn't initially, till you mentioned it.

The "Resource Variable Name:" that I listed happened to be "Resource variable:" so my next question is how can I put this into a loop, because it is not identical throughout. It can be either of "Resource variable:" or "Resource Variable Name:".

Thanks.
 

nawk -v first='(Resource variable:)|(Resource Variable Name:)' -v sought=IBM -f loose.awk sampleFile.txt

Code:
$0 ~ first {
    if ( match($0, sought) ) {
      getline;
      print
    }
}

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

Part and Inventory Search

Sponsor

Back
Top