Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: awk tutoria...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 11 Topic 2222 of 2236
Post > Topic >>

Re: awk tutorial confusion

by Ed Morton <morton@[EMAIL PROTECTED] > Apr 14, 2008 at 06:21 AM

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.




 11 Posts in Topic:
awk tutorial confusion
r <inpost@[EMAIL PROTE  2008-04-14 01:53:41 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-14 06:00:16 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-14 06:21:55 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-16 15:13:08 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-16 17:12:31 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-17 20:11:28 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-17 23:48:23 
OT: Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-17 00:22:15 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-16 14:28:50 
Re: awk tutorial confusion
r <inpost@[EMAIL PROTE  2008-04-16 14:42:52 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-17 20:02:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 11:40:31 CDT 2008.