From owner-freebsd-questions@FreeBSD.ORG Mon Dec 17 13:16:00 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 84E2C44C for ; Mon, 17 Dec 2012 13:16:00 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 3C6FF8FC12 for ; Mon, 17 Dec 2012 13:16:00 +0000 (UTC) Received: from r56.edvax.de (port-92-195-51-39.dynamic.qsc.de [92.195.51.39]) by mx02.qsc.de (Postfix) with ESMTP id 698D12761C; Mon, 17 Dec 2012 14:15:58 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id qBHDG0u7002247; Mon, 17 Dec 2012 14:16:00 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Mon, 17 Dec 2012 14:16:00 +0100 From: Polytropon To: Jack Mc Lauren Subject: Re: using AWK Message-Id: <20121217141600.206f39e9.freebsd@edvax.de> 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> Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "freebsd-questions@freebsd.org" , Ben Cottrell X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Dec 2012 13:16:00 -0000 On Mon, 17 Dec 2012 04:22:21 -0800 (PST), Jack Mc Lauren wrote: > Yes, I want the number to go into an awk variable. > [...]=20 > This is what i wrote: >=20 >=20 > #! /bin/sh >=20 > filename=3D$0 > awk 'getline no < filename; print no' >=20 > But when I run this script >=20 > sh /awk_no.sh /var/no.txt >=20 > I have this error : >=20 > awk: syntax error at source line 1 > =A0context is > =A0 =A0 =A0 =A0 getline no < filename; >>> =A0print <<< =A0no > awk: bailing out at source line 1 >=20 > Thank you :) The error is obvious: You need to transition $filename from the sh level into the awk script, i. e. the file name string (in your example, "/var/no.txt") must be visible inside the awk script. You're using a variable called filename which is uninitialized (empty). You can either define the file name statically in the awk script, or use ${filename} in the script (use double quotes to allow resolution). Also note that $0 is the name by which the script has been called. $1 is the 1st parameter. --=20 Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...