Talk About Network

Google


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: Separating ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 2166 of 2317
Post > Topic >>

Re: Separating rules with semicolons

by Ed Morton <morton@[EMAIL PROTECTED] > Feb 18, 2008 at 08:00 AM

On 2/18/2008 6:54 AM, Spiros Bousbouras wrote:
> On page 22 of "Effective AWK programming" we read:
> 
>        When awk statements within one rule are
>        short, you might want to put more than one
>        of them on a line. This is accomplished by
>        separating the statements with a semicolon
>        (`;').  This also applies to the rules
>        themselves. Thus, the program shown at the
>        start of this section could also be written
>        this way:
>       /12/ { print $0 } ; /21/ { print $0 }
>        NOTE: The requirement that states that rules
>        on the same line must be separated with a
>        semicolon was not in the original awk language;
>        it was added for consistency with the treatment
>        of statements within an action.
> 
> But when I try
> gawk --posix  '/a/ {print "swds"} /b/ {print "1234"}'
> it works fine. Same if I omit "--posix". If it is a
> requirement then why does omitting semicolons work ?

It's not required, I don't know why the book claims it is. I suspect it's
just
bad wording and a bad example. It's only required when you need to
explicitly
mark the end of a condition/action/rule upon removing a newline, e.g. to
change
this:

/l2/
{ print $0 }

to one line would need to be:

/l2/ ; { print $0 }

rether than the completely different program:

/l2/ { print $0 }

Regards,

	Ed.
 




 4 Posts in Topic:
Separating rules with semicolons
Spiros Bousbouras <spi  2008-02-18 04:54:11 
Re: Separating rules with semicolons
Ed Morton <morton@[EMA  2008-02-18 08:00:55 
Re: Separating rules with semicolons
Steffen Schuler <schul  2008-02-20 00:03:24 
Re: Separating rules with semicolons
Janis Papanagnou <Jani  2008-02-20 19:19: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 Jul 25 15:02:39 CDT 2008.