Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

pls explain what action part is missing here
Platform:
C:\>ver
Microsoft Windows 2000 [Version 5.00.2195]
G:\>gawk --version
GNU Awk 3.1.0


I am learning awk for use in batch files as an quick alternative to Perl
scripts to do text searches at work. This is done on a Win32 platform and
*nix is _NOT_ available or an option due to C*O level political decisions.

I understand that awk requires a series of rules which are subdivided as a
pattern {action} for each rule. BEGIN and END are regarded as patterns 
and
require actions. The documentation at
http://www.gnu.org/software/gawk/ma...on-Overview.htm is
somewhat contradictory in that for an omitted action the curly braces can
be omitted as well although it is followed two lines later with an example
of empty braces as an empty action.

Due to the coding practices at work, I was putting the opening curly brace
on the line under the keywords BEGIN and END. Such as:

# this doesn't run on GnuWin32 gawk
BEGIN
{
FS = "@"
}


This was causing gawk to balk with "warning: BEGIN blocks must have an
action part". After much head banging on keyboard and doubting of sanity
for attempting to use gawk, I found that if the opening curly brace was on
the same line as the keyword BEGIN, then it would run as advertised.

# this DOES run on GnuWin32 gawk
BEGIN {
FS = "@"
}

I cannot find this documented in any of the fsf.org documentation.

My question is '¿Is this a vagarity of GnuWin32 gawk or of gawk in
general?'

TIA

Will

--
¡Microsoft delenda est!

Report this thread to moderator Post Follow-up to this message
Old Post
Will Ganz
03-20-04 01:23 AM


Re: pls explain what action part is missing here
"Will Ganz" <wganz__trash_MAPS¶_@texoma.net> wrote...
...
>http://www.gnu.org/software/gawk/ma...on-Overview.htm is
>somewhat contradictory in that for an omitted action the curly braces can
>be omitted as well although it is followed two lines later with an example
>of empty braces as an empty action.

You misread the docs. From the url above:

"An omitted action is equivalent to { print $0 }:

/foo/  { }     match foo, do nothing --- empty action
/foo/          match foo, print the record --- omitted action"


>Due to the coding practices at work, I was putting the opening curly brace
>on the line under the keywords BEGIN and END. Such as:
...

awk is *NOT* C. Never forget this.

>I cannot find this documented in any of the fsf.org documentation.

Really? Try

http://www.gnu.org/software/gawk/ma...ng-Started.html

which states:

"Syntactically, a rule consists of a pattern followed by an action. The
action is enclosed in curly braces to separate it from the pattern. Newlines
usually separate rules. Therefore, an awk program looks like this:

pattern { action }
pattern { action }
.."

Also, see

http://www.gnu.org/software/gawk/ma...ents-Lines.html

which states:

"Most often, each line in an awk program is a separate statement or separate
rule, like this:

awk '/12/  { print $0 }
/21/  { print $0 }' BBS-list inventory-shipped

However, gawk ignores newlines after any of the following symbols and
keywords:

,    {    ?    :    ||    &&    do    else

A newline at any other point is considered the end of the statement.1"

Since patterns must be valid expressions or nothing at all, and no valid
expression could end with any of the forgoing tokens, it follows that gawk
won't ignore newlines after patterns.

Sometimes you need to connect the dots yourself.

>My question is '¿Is this a vagarity of GnuWin32 gawk or of gawk in
>general?'

Common to all awks, not just gawk, Win32 or otherwise.



Report this thread to moderator Post Follow-up to this message
Old Post
Harlan Grove
03-20-04 01:23 AM


Re: pls explain what action part is missing here
Will Ganz wrote:

> # this doesn't run on GnuWin32 gawk
> BEGIN
> {
>     FS = "@"
> }
>
>
> This was causing gawk to balk with "warning: BEGIN blocks must have an
> action part". After much head banging on keyboard and doubting of sanity
> for attempting to use gawk, I found that if the opening curly brace was on
> the same line as the keyword BEGIN, then it would run as advertised.
>
> # this DOES run on GnuWin32 gawk
> BEGIN {
>      FS = "@"
> }


As far my knowledge goes this is standard for any awk:

BEGIN \
{
FS = "@"
}

and

BEGIN {
FS = "@"
}

are valid syntaxes for AWK

BEGIN
{
FS = "@"
}

is not.


Antonio

--
Antonio Dell'elce
http://www.dellelce.com/MyHome/
Ph: (IT) +39 347 6761377 (UK) +44 7816 216 963
"Timendi causa est nescire"

Report this thread to moderator Post Follow-up to this message
Old Post
Antonio Dell'elce
03-20-04 01:23 AM


Re: pls explain what action part is missing here
Antonio,

Thanks for the reply! Got it figured out and off to another awk philosphy
problem.

Regards,

Will

--
¡Microsoft delenda est!

Report this thread to moderator Post Follow-up to this message
Old Post
Will Ganz
03-20-04 01:23 AM


Re: pls explain what action part is missing here
Antonio Dell'elce <antonio@dellelce.com> wrote in message news:<bVIXb.9011$Kc3.283665@twist
er2.libero.it>...
> Will Ganz wrote:
> 
>
>
> As far my knowledge goes this is standard for any awk:
>
> BEGIN \
>    {
>       FS = "@"
>    }
>
> and
>
> BEGIN {
>           FS = "@"
>        }
>
> are valid syntaxes for AWK
>
> BEGIN
> {
>     FS = "@"
> }
>
> is not.
>
>
> Antonio

FYI --

The syntax:
BEGIN
{
FS = "@"
}


seems to work fine in TAWK.

Report this thread to moderator Post Follow-up to this message
Old Post
TKK
03-20-04 01:23 AM


Re: pls explain what action part is missing here
> seems to work fine in TAWK.

Unfortunately, TAWK is $199 for a single license and $599 for a 5 pak.

You should have seen the conference that we had just to get it to where I
could use grep. And this is a company that has shut off all Internet access
since the COO is convinced that we got hit by the NIMDA virus from people
using Internet Explorer and not that it was due to holes in IIS. The sys
admins wanted to take out all of the floppy & CDROM drives for they were
convinced that the Klez virus was from someone bringing a music CD in.

Sigh.....

--
¡Microsoft delenda est!

Report this thread to moderator Post Follow-up to this message
Old Post
Will Ganz
03-20-04 01:23 AM


Re: pls explain what action part is missing here
In article <Xns9492C098AF823wganztexomanet@129.250.170.96>,
Will Ganz  <wganz__trash_MAPS¶_@texoma.net> wrote: 
>
>Unfortunately, TAWK is $199 for a single license and $599 for a 5 pak.
>
>You should have seen the conference that we had just to get it to where I
>could use grep. And this is a company that has shut off all Internet access
>since the COO is convinced that we got hit by the NIMDA virus from people
>using Internet Explorer and not that it was due to holes in IIS. The sys
>admins wanted to take out all of the floppy & CDROM drives for they were
>convinced that the Klez virus was from someone bringing a music CD in.

What any of that has to do with TAWK, I fail to see.

The game of computing is turning into a big game of "place the blame",
because of the fact that the obviously correct answer is the one that
is untenable to hold.

But, anyway, to get back to on topic, I have these comments:
1) TAWK is worth every penny.
2) The hard part today is actually finding it.  As far as I can
tell, and please, someone tell me if I'm wrong, the company no
longer exists.  I've tried several times over the past year or
so to contact them, to no avail.
3) The construct noted (shown below) is not legal AWK, and if TAWK
accepts it, well, that's a whatever you want to call it...

BEGIN
{
print 1+2
}

P.S.  TAWK does indeed accept this (it prints 3 and exits), but gawk sez
"Warning: BEGIN blocks must have an action part", but then *fails* to read
the terminal and print 3 for every input line.  I would assume that it
should, on the assumption that warnings should be non-fatal.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
03-20-04 01:23 AM


Re: pls explain what action part is missing here
Kenny,

Apologies for belly aching about the obvious shortcomings of where I work
and not simply stating that introducing a commercial version of awk is not
a possibility.

The price list on the web site (http://www.tasoft.com/) that includes TAWK
was effective "January 1, 2003" although I have not attempted to contact
them.

Will

--
¡Microsoft delenda est!

Report this thread to moderator Post Follow-up to this message
Old Post
Will Ganz
03-20-04 01:23 AM


Re: pls explain what action part is missing here
In article <c0ugkp$g27$1@yin.interaccess.com>,
Kenny McCormack <gazelle@interaccess.com> wrote:
>But, anyway, to get back to on topic, I have these comments:
>	1) TAWK is worth every penny.
>	2) The hard part today is actually finding it.  As far as I can
>	   tell, and please, someone tell me if I'm wrong, the company no
>	   longer exists.  I've tried several times over the past year or
>	   so to contact them, to no avail.

Their web site is still up: http://www.tasoft.com, including phone numbers
and mailing address.  I suppose worst case you could get on a plane, go to
Portland, and try to walk into their door. (:-)

>	3) The construct noted (shown below) is not legal AWK, and if TAWK
>	   accepts it, well, that's a whatever you want to call it...
>
>BEGIN
>{
>print 1+2
>}
>
>P.S.  TAWK does indeed accept this (it prints 3 and exits), but gawk sez
>"Warning: BEGIN blocks must have an action part", but then *fails* to read
>the terminal and print 3 for every input line.  I would assume that it
>should, on the assumption that warnings should be non-fatal.

I have just changed this to remove the word "warning".  I used the wrong
routine to print the error message.  Thanks for pointing this out.

Arnold
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd.	arnold AT skeeve DOT com
P.O. Box 354		Home Phone: +972  8 979-0381	Fax: +1 530 688 5518
Nof Ayalon		Cell Phone: +972 51  297-545
D.N. Shimshon 99785	ISRAEL

Report this thread to moderator Post Follow-up to this message
Old Post
Aharon Robbins
03-20-04 01:23 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:48 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.