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

Re: awk tutorial confusion

by Ed Morton <morton@[EMAIL PROTECTED] > Apr 17, 2008 at 11:48 PM

On 4/17/2008 7:11 PM, Bruce Barnett wrote:
> Ed Morton <morton@[EMAIL PROTECTED]
> writes:
> 
> 
>>>-------------
>>>#!/bin/sh
>>>awk '{print $c}' c=${1:-1}
>>>------------
>>>
>>>(it defaults to printing column #1 if no arguments are given.)
>>
>>Thats fine as an example of a shell script, but it isn't a good example
of an
>>awk script since it relies on the OS to do some processing. I don't know
what
>>the Windows syntax is to accomplish the same thing but the general awk
script
>>would be the much wordier:
>>
>>    awk -v c="$1" 'BEGIN{ c=(c==""?1:c) }{ print $c }'
> 
> 
> Yes, but I didn't want to scare away beginners by suggesting this as
> their very first AWK script.

Agreed. As I said in the part you snipped:

> but I wouldn't even be using this as an example in an "_AWK_" tutorial.
> 


> As r <inpost@[EMAIL PROTECTED]
> implies, there is a fine balance between
> assuming too much and going too fast when writing a tutorial. 
> 
> I'll make some more changes in the tutorial as you suggest - the best
> I can. 

OK, but it sounds like you still think doing the
jumping-back-and-forth-between-shell-and-awk thing is an acceptable way to
pass
the value of shell variables to awk while FWIW I think that way should
never be
used as it needlessly introduces insidious bugs with obscure error
messages
depending on the settings of the variable, and it just cannot be used at
all
when your awk script is stored in a file and invoked with awk -f. I do
understand you want to show one way that works in sed and awk, but the
reality
is that the way your describing actually works in neither of them for some
values of the variable, it's just that in awk there's a better way that
DOES
work. Whatever you decide....

	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:37:06 CDT 2008.