using /bin/sh vars in awk
Scott "gaspo" Gasparian
gaspar at inf.ethz.ch
Tue Apr 2 22:14:26 AEST 1991
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 at 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 at scri.fsu.edu | past,so dry your tears I say. No woman, No cry." -BMW |
\----------------------------------------------------------------------------/
More information about the Comp.unix.shell
mailing list