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 9 of 11 Topic 2222 of 2236
Post > Topic >>

Re: awk tutorial confusion

by Bruce Barnett <spamhater131+spamtrap@[EMAIL PROTECTED] > Apr 16, 2008 at 02:28 PM

r <inpost@[EMAIL PROTECTED]
> writes:

> Readers,
>
> I am reading a tutorial, to learn how to use awk (http://
> www.grymoire.com/Unix/Awk.html).
>
> I've copied the following text and saved in the filenames shown:


I think you are a little too eager here.  In the tutorial in the next
section I describe several ways to execute an awk script.

See "Executing an AWK script" in
http://www.grymoire.com/Unix/Awk.html#uh-2

>
> $ awk -f fileowner.awk
> awk: fileowner.awk:2: awk'
> awk: fileowner.awk:2:    ^ invalid char ''' in expression

I described three different ways to write an AWK script

Bourne shell (and POSIX shells)
        http://www.grymoire.com/Unix/Scripts/awk_example1.sh

(C shell - not recommended)
        http://www.grymoire.com/Unix/Scripts/awk_example1.csh

(AWK script)
        http://www.grymoire.com/Unix/Scripts/awk_example1.awk

You are using AWK to execute a Bourne shell script.  I updated my
tutorial to make this clearer. I hope this helps.


Also - in the Dynamic Variables section, when you used 

>fileowner3:
>#!/bin/sh
>column=$1
>awk '{print $column}'

You have to read the next few paragraphs. (I'll make some changes to
make this more obvious).

I have the comment

Only one problem: the script doesn't work.  The value of the "column"
variable is not seen by AWK. Change "awk" to "echo" to check. 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'}'

Hope this helps.

- Bruce
** Posted from http://www.teranews.com
**




 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:28:45 CDT 2008.