Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Dec 2012 20:17:33 +0000
From:      RW <rwmaillists@googlemail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: using AWK
Message-ID:  <20121218201733.06f78f1f@gumby.homeunix.com>
In-Reply-To: <18B0C79B-AF04-48D1-AF26-1B8A8B3641C1@fisglobal.com>
References:  <1355744359.61103.YahooMailNeo@web160104.mail.bf1.yahoo.com> <18B0C79B-AF04-48D1-AF26-1B8A8B3641C1@fisglobal.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 17 Dec 2012 08:16:26 -0800
Devin Teske wrote:

> 
> On Dec 17, 2012, at 3:39 AM, Jack Mc Lauren wrote:
> 
> > Hi guys
> > 
> > How can I read a file which contains a number and assign that
> > number to a variable via awk programming? By the way, I want to use
> > this awk program in a shell script.
> > 
> > Thanks in advance
> 
> Try this:
> 
> awk -v file=/etc/ttys 'BEGIN { getline line <file; printf "First line
> from %s: %s\n", file, line }'
> 
Semms a bit complicated when you could set the awk variable directly
e.g.

$ echo 42 > /tmp/f
$ awk -v x=`cat /tmp/f`  'BEGIN{ print x+1 }'
43





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