Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Dec 2012 14:16:00 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Jack Mc Lauren <jack.mclauren@yahoo.com>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>, Ben Cottrell <tamino@wolfhut.org>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121217141600.206f39e9.freebsd>