[HPADM] dynamic regex matching in awk

From: Thad Schultz (tschul@woodward.com)
Date: Wed Nov 20 2002 - 16:04:21 EST


#!/usr/bin/ksh

I have a script that matches a part number the user enters against a file
with two tab separated columns. Column 1 contains a part number and column
2 contains a revision letter. The part number can look like 1751-896 or
1751-923|ext. I want to match what is entered up to the first "|" or the
end of the column. If they enter a partial number (1751-9) I do not want a
match. I've tried the following script and it finds numbers that have a "|"
in them. It does not find numbers without the "|" in them. What am I doing
wrong or what are other ways to do what I'm trying to do?

TIA

PN_LIST=pn_list.txt

printf "Enter part number for search: "
read PART

RESULT=$(awk -v PART="$PART[\|\$]" '$1~PART {print $2}' $PN_LIST)

.
.
.
<processing of $RESULT>
.
.
.

Thad Schultz
EDA Librarian / Sys Admin
Woodward Industrial Controls
tschul@woodward.com
ph (970)498-3570
fax (970)498-3077
www.woodward.com

***
The information in this e-mail is confidential and intended solely for the
individual or entity to whom it is addressed. If you have received this
e-mail in error please notify the sender by return e-mail, delete this
e-mail, and refrain from any disclosure or action based on the information.
****

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:22 EDT