[HPADM] SUMMARY: dynamic regex matching in awk

From: Thad Schultz (tschul@woodward.com)
Date: Thu Nov 21 2002 - 09:27:34 EST


I got my script to work.

I realize that the $ in my original regex is suppose to anchor to the end of
the line but I thought that awk would treat the end of the first column as
the end of the line since I was matching my regex against $1 and I figured
awk new nothing about entire lines. I guess my thinking was wrong. I
changed the $ in my regex to a tab character and now it works like I wanted
it to:

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

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

-----------------------------------

Original Question:

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?

#!/usr/bin/ksh

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>
.

***
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