Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!cernvax!chx400!chx400!bernina!neptune!inf.ethz.ch!gaspar From: gaspar@inf.ethz.ch (Scott "gaspo" Gasparian) Newsgroups: comp.unix.shell Subject: using /bin/sh vars in awk Summary: once agiain, need to put sh vars in awk Message-ID: <27814@neptune.inf.ethz.ch> Date: 2 Apr 91 12:14:26 GMT Article-I.D.: neptune.27814 Sender: news@neptune.inf.ethz.ch Reply-To: gaspar@inf.ethz.ch (Scott "gaspo" Gasparian) Distribution: comp.unix.shell Organization: Twilight-Zone-Algorithms-Incorporated Lines: 36 ok, I know this came up awhile ago, and I dont want to bring it up again. However, not enuf disk to keep articles around, and I forgot the answer: Question: what syntax do I have to use to get awk to take /bin/sh variables in a shell script? Example: given a /bin/sh script, and an awk command in it somewheres, and i need to pass the var ${fred} to awk, what should the following line look like? fred="barney" wilma=`cat ${file1} | awk '{if($1== fred ){print("match")}}' ^^^^ what I need is how to expand fred_| to get awk to replace it with the string "barney" Since this already came up, just email me the answer. I've already tried ${fred}, $fred, "${fred}" and a couple other combos. thanks --gaspo. BTW, the example is just that, I don't need a different way to solve the example. just get the vars to awk. /----------------------------------------------------------------------------\ | Scott "gaspo" Gasparian -- System Administrator | _>________ _<________ | | Dept. Informatik, Eidg. Techn. Hochschule, Zurich |/[][][][][]\/[][][][][]\| | ETH-Zentrum, CH-8092 Zurich. T# 01-01-254-7205 |`oo------oo'`oo------oo'| | gaspar@inf.ethz.ch | "Good friends we've had, or good friends we've lost, | | ..!ethz-inf!gaspar | along the way.In this proud land,you can't forget your| | gaspo@scri.fsu.edu | past,so dry your tears I say. No woman, No cry." -BMW | \----------------------------------------------------------------------------/