Date: Mon, 17 Dec 2012 07:56:17 -0800 From: Ben Cottrell <tamino@wolfhut.org> To: Jack Mc Lauren <jack.mclauren@yahoo.com> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: Re: using AWK Message-ID: <30513BAB-051F-47B1-BE77-3F2DCF76375F@wolfhut.org> In-Reply-To: <1355746941.52411.YahooMailNeo@web160103.mail.bf1.yahoo.com> References: <1355744359.61103.YahooMailNeo@web160104.mail.bf1.yahoo.com> <8EA88B4E-9C21-4CF7-9AB0-87663AB876F8@wolfhut.org> <1355746941.52411.YahooMailNeo@web160103.mail.bf1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Dec 17, 2012, at 04:22, Jack Mc Lauren <jack.mclauren@yahoo.com> wrote: > This is what i wrote: OK -- I'm adjusting my assumptions about what you're trying to do. :-) Bear with me: > #! /bin/sh > > filename=$0 So (a) there's only one input file, not multiple... and (b) it should come from the command line of the shell script wrapper. Right? > awk 'getline no < filename; print no' If there's only one input file, then this is super easy and you don't even need any of the getline or close stuff. Try: filename=$1 awk '{no = $0; print no;}' $filename In the shell script context (outside the awk), $1 refers to the first command line parameter of the script. You don't want $0 there. On the other hand, *inside* the awk part, dollar-sign variables have a completely different meaning. $0 in *awk* (not sh) means "the entire contents of each line of the input file". So if your file had multiple lines, that block would run multiple times. But since I'm guessing your file only has one line (that being the number in question), the awk block will only run once. ~Ben
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?30513BAB-051F-47B1-BE77-3F2DCF76375F>