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!

shell variable false positives

Status
Not open for further replies.

pb0y

Technical User
Feb 27, 2002
16
US
Hi,

I am scanning certain tables in a comma-delimited file for some number (shell variable $1) in the 3 field of each record and then getting the index number of that record (field $1) when it finds a match.

nawk '/table1/, /table2/' tempfile | nawk -v X=$1 'BEGIN {FS=","} $3 ~ X {print $1}

The problem I am running into is I want to only retrieve the records for X and not when X is part of some other number. (If x is 10, it returns true for 10, 100, 110 etc).

I've tried regular expressions but I can't seem to find the correct syntax.

nawk '/start/, /stop/' tempfile | nawk -v X=$1 'BEGIN {FS=","} $3 ~ /^X$/{print $1}

Any help would be appreciated.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top