using AWK
Polytropon
freebsd at edvax.de
Mon Dec 17 13:16:00 UTC 2012
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.
> [...]
> This is what i wrote:
>
>
> #! /bin/sh
>
> filename=$0
> awk 'getline no < filename; print no'
>
> But when I run this script
>
> sh /awk_no.sh /var/no.txt
>
> I have this error :
>
> awk: syntax error at source line 1
> context is
> getline no < filename; >>> print <<< no
> awk: bailing out at source line 1
>
> 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.
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions
mailing list