Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!hao!oddjob!gargoyle!ihnp4!att-cb!clyde!ho95e!wcs From: wcs@ho95e.ATT.COM (Bill.Stewart) Newsgroups: comp.unix.questions Subject: Re: Expansion of variables in sh scripts Message-ID: <2004@ho95e.ATT.COM> Date: 25 Feb 88 23:06:03 GMT References: <1159@valhalla.ee.rochester.edu> <2003@ho95e.ATT.COM> Reply-To: wcs@ho95e.UUCP (46323-Bill.Stewart,2G218,x0705,) Organization: AT&T Bell Labs 46133, Holmdel, NJ Lines: 34 Keywords: Forward quote, backword quote, double quote, auuuuuuuuugh! Summary: Awk? Phfft! In article <1159@valhalla.ee.rochester.edu> badri@valhalla.ee.rochester.edu (Badri Lokanathan) writes: >Well, after several years of shell script writing, I thought I knew >everything about it, but I was wrong! >Given a 2 column file of data in two columns, the columns separated >by blanks. A script is desired which, among other things, searches >for a word in the I column and outputs the corresponding entry in >the II column. (I realize your question was about why your awk script didn't get passed the correct arguments.) But why use awk at all? It's very flexible, but much slower than egrep or sed. For this application, I'd recommend : Usage: myname pattern file egrep "^$1 " $2 | cut -f2 -d" " Even if you decide to use awk instead of cut to extract the second column (and presumably do summaries or other useful work), you'll speed the program up significantly by using egrep to reduce the amount of data that awk has to process. Alternatively, you can write it in shell (which won't be real fast either.) : Usage: myname pattern file pattern="$1"; shift cat $* | while read col1 col2 ; do if [ "$col1" = "$pattern" ] then echo $col2 fi done If your shell doesn't provide test ([) as a builtin, use case instead. -- # Thanks; # Bill Stewart, AT&T Bell Labs 2G218, Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs