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!

Filter results in awk

Status
Not open for further replies.

aaaandy

Technical User
Apr 1, 2011
1
GB
Hi guys,

I'm a complete noob to awk and have a question which I'd really appreciate help on

I have to search a file for a list of specific words which are separated by a semicolon ( word1;word2;word3;.... ) and is achieved by:

Code:
n = split ( list, a, ";" )
for ( i = 1; i <= n; i++ ) 
if (index( $0,a[ i ]) != 0)
{
[i]do something if found[/i]
}



This does return all the places in the file where the words are present and works great. However the next step is to filter through these results as some of the results returned are actually allowed and so I do not want to return them from the search.

To do this, I have a another set of "allowed words" separated by a semi-colon but am having trouble achieving it and am stuck for ideas.

Any ideas?


I'm using nawk within a ksh script to achieve this, hope this is clear enough...
 


In your "do something if found" section, look for the allowed words the same way you are searching for the other words.
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top