From owner-freebsd-questions@FreeBSD.ORG Mon Dec 17 15:56:19 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 096447FA for ; Mon, 17 Dec 2012 15:56:19 +0000 (UTC) (envelope-from tamino@wolfhut.org) Received: from pendor.wolfhut.org (pendor.wolfhut.org [173.228.91.225]) by mx1.freebsd.org (Postfix) with ESMTP id DCB188FC0C for ; Mon, 17 Dec 2012 15:56:17 +0000 (UTC) Received: from [192.168.42.100] (173-228-91-224.static.sonic.net [173.228.91.224]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by pendor.wolfhut.org (Postfix) with ESMTPSA id 6E013DBB61; Mon, 17 Dec 2012 07:56:17 -0800 (PST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: using AWK From: Ben Cottrell In-Reply-To: <1355746941.52411.YahooMailNeo@web160103.mail.bf1.yahoo.com> Date: Mon, 17 Dec 2012 07:56:17 -0800 Content-Transfer-Encoding: 7bit Message-Id: <30513BAB-051F-47B1-BE77-3F2DCF76375F@wolfhut.org> References: <1355744359.61103.YahooMailNeo@web160104.mail.bf1.yahoo.com> <8EA88B4E-9C21-4CF7-9AB0-87663AB876F8@wolfhut.org> <1355746941.52411.YahooMailNeo@web160103.mail.bf1.yahoo.com> To: Jack Mc Lauren X-Mailer: Apple Mail (2.1499) Cc: "freebsd-questions@freebsd.org" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Dec 2012 15:56:19 -0000 On Dec 17, 2012, at 04:22, Jack Mc Lauren 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