On 4/14/2008 3:53 AM, r wrote:
> Readers,
>
> I am reading a tutorial, to learn how to use awk (http://
> www.grymoire.com/Unix/Awk.html).
I just took a look at that tutorial and I can see why you're confused! It
does
indeed tell you:
---------------
we can make this into a typical AWK program:
BEGIN { print "File\tOwner"," }
{ print $8, "\t", $3}
END { print " - DONE -" }
I'll improve the script in the next sections, but we'll call it
"FileOwner."
......
the invocation would be
ls -l | FileOwner
-----------------
which is nonsense as, after you fix the syntax error at the end of the
BEGIN
line, you'd need to invoke the above using
ls -l | awk -f FileOwner
and then later tells you:
-----------------
If you wanted to break a long line into two lines at any other place, you
must
use a backslash:
.....
The Bourne shell version would be
#!/bin/sh
awk '
BEGIN { print "File\tOwner" }
{ print $8, "\t",
$3}
END { print "done"}
'
-----------------
which is missing the backslash it's trying to show you to use:
#!/bin/sh
awk '
BEGIN { print "File\tOwner" }
{ print $8, "\t", \
$3}
END { print "done"}
'
It then goes on to say:
----------------
The first version of the program, which we will call "Column," looks like
this:
#!/bin/sh
column=$1
awk '{print $column}'
.....
Only one problem: the script doesn't work. ... You need to turn off the
quoting
when the variable is seen. This can be done by ending the quoting, and
restarting it after the variable:
#!/bin/sh
column=$1
awk '{print $'$column'}'
----------------------
which is the worst possible way to pass the value of a shell variable to
an awk
program (see http://cfaj.freeshell.org/shell/cus-faq-2.html#24
for the
right way).
Since all of that is just in the opening section, I wouldn't trust the
rest of
this "tutorial"....
Get the book Effective Awk Programming, Third Edition By Arnold Robbins,
http://www.oreilly.com/catalog/awkprog3/
and if you need to do some awk
reading
before it arrives, take a look at
http://www.gnu.org/software/gawk/manual/gawk.html.
Ed.


|