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

Script cause gawk to abend
OS - W2k Adv Server
gawk - ver 3.1.0.2

I was continuing with my rewrite of the awk manual to add GnuWin32 examples
and hit upon a script that causes gawk to abend.

<quote>
Node: Printf Examples

The fact that the same format specification is used three times can be
emphasized by storing it in a variable, like this:

awk 'BEGIN { format = "%-10s %s\n"
printf format, "Name", "Number"
printf format, "----", "------" }
{ printf format, $1, $2 }' BBS-list
</quote>

My attempt at a GnuWin32 conversion was:

C:\>awk "BEGIN { format = \"%-14s %s\n\" printf format, \"Name\",\"Numb
er"
printf format, \"----\", \"------\" } { printf format, $1, $2
}" BBS-list.txt


Which resulted in this message:
 ****************************************
****************************
awk: cmd. line:1: BEGIN { format = "%-14s %s\n" printf format, "Name",
"Number"
printf format, "----", "------" } { printf format, $1, $2 }
awk: cmd. line:1:                               ^ parse error
awk: cmd. line:1: BEGIN { format = "%-14s %s\n" printf format, "Name",
"Number"
printf format, "----", "------" } { printf format, $1, $2 }
awk: cmd. line:1:
^ parse error
awk: cmd. line:1: fatal error: internal error

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
 ****************************************
****************************

Apologies for the wrapping but only got 78 columns to play with here with
Xnews. It appears that gawk doesn't like having the format-control letters
assigned to a variable.

Anyone have any ideas where I need to research this one?

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: Script cause gawk to abend
In article <Xns949DD7AF53338wganztexomanet@129.250.170.83>,
Will Ganz  <wganz__trash_MAPS¶_@texoma.net> wrote:
>Please contact the application's support team for more information.
> ****************************************
****************************
>
>Apologies for the wrapping but only got 78 columns to play with here with
>Xnews. It appears that gawk doesn't like having the format-control letters
>assigned to a variable.

Or, you could be missing a few semicolons...

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


Re: Script cause gawk to abend
In article <Xns949DD7AF53338wganztexomanet@129.250.170.83>,
Will Ganz  <wganz__trash_MAPS¶_@texoma.net> wrote:
>OS - W2k Adv Server
>gawk - ver 3.1.0.2
>
>I was continuing with my rewrite of the awk manual to add GnuWin32 examples
>and hit upon a script that causes gawk to abend.
>
><quote>
>Node: Printf Examples
>
>The fact that the same format specification is used three times can be
>emphasized by storing it in a variable, like this:
>
>     awk 'BEGIN { format = "%-10s %s\n"
>                  printf format, "Name", "Number"
>                  printf format, "----", "------" }
>          { printf format, $1, $2 }' BBS-list
></quote>
>
>My attempt at a GnuWin32 conversion was:
>
>C:\>awk "BEGIN { format = \"%-14s %s\n\" printf format, \"Name\",\"Num
ber"
>printf format, \"----\", \"------\" } { printf format, $1, $2
>}" BBS-list.txt
>
>
>Which resulted in this message:
> ****************************************
****************************
>awk: cmd. line:1: BEGIN { format = "%-14s %s\n" printf format, "Name",
>"Number"
>printf format, "----", "------" } { printf format, $1, $2 }
>awk: cmd. line:1:                               ^ parse error
>awk: cmd. line:1: BEGIN { format = "%-14s %s\n" printf format, "Name",
>"Number"
>printf format, "----", "------" } { printf format, $1, $2 }
>awk: cmd. line:1:
>^ parse error
>awk: cmd. line:1: fatal error: internal error

First, try putting the awk program into a separate file and testing it
with
awk -f t.awk BBS-list.txt

This works OK for me under Linux with gawk 3.1.[0-3].  If it fails,
try upgrading to gawk 3.1.3 (the current version) and if it still fails,
talk to the GNUwin32 developers, since, as far as I can tell, it's not
a problem in gawk itself.

Hmm, as Kenny said, you're missing semicolons:

>C:\>awk "BEGIN { format = \"%-14s %s\n\" printf format, \"Name\",\"Number"[/co
lor]
^^^^^

>printf format, \"----\", \"------\" } { printf format, $1, $2
>}" BBS-list.txt

I bet a semicolon before the printf will do the trick.  In any case,
you're better off under dos/windoes with the awk program in a separate file.

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


Re: Script cause gawk to abend
> I bet a semicolon before the printf will do the trick.  In any case,
> you're better off under dos/windoes with the awk program in a separate
> file.

The comments and corrections are most appreciated. By placing a semicolon
before each 'printf' immediately cured the problem. Thanks to both of you fo
r
your input.

This is what worked:

C:\>awk "BEGIN { format = \"%-14s %s\n\"; printf format, \"Name\", \"Nu
mber
\"; printf format, \"----\", \"------\" } { printf format, $1, $2 }" BB
S-
list.txt

> try putting the awk program into a separate file

That has been my observation also since I've taken up GnuWin32 gawk about a
month ago. Just that I'm trying to learn howto translate the *nix dialect of
awk into Win32 pidgin awk since all the examples are in the *nix dialect.


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


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:03 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.