Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!ox.com!math.fu-berlin.de!unidui!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.unix.shell Subject: Re: using /bin/sh vars in awk Message-ID: <1110@mwtech.UUCP> Date: 1 May 91 13:23:24 GMT References: <27814@neptune.inf.ethz.ch> <1695@targon.UUCP> <1991Apr29.122714.17138@athena.mit.edu> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 22 In article <1991Apr29.122714.17138@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article , maki@void.jit.dec.com (Watanabe Maki) writes: >|> If your awk is nawk(New Awk), it's easy. >|> >|> ... | nawk '{if ($1 == fred) command}' fred="barney" > > Actually, this syntax will work with nearly any version of awk, not just >nawk. It was available, albeit undocumented, in even the earliest distributed >versions. Minor nitpick: But be sure to add a "-" if you want to have stdin processed. ... | nawk '{if ($1 == fred) command}' fred="barney" - # Important little thing here, watch closely! -------^ Reason: awk in its older versions is a bit stupid about the command line arguments that are assignments to awk-variables and counts them as if they were file arguments, failing process stdin as default if there are any such assignments but no file arguments. The trick with explicitly naming stdin solves this problem. -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83