using AWK
RW
rwmaillists at googlemail.com
Tue Dec 18 20:42:28 UTC 2012
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
More information about the freebsd-questions
mailing list