For Programmers: Free Programming Magazines  


Home > Archive > AWK > March 2004 > Script cause gawk to abend









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Script cause gawk to abend
Will Ganz

2004-03-19, 8:23 pm

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\",\"Number"
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!
Kenny McCormack

2004-03-19, 8:23 pm

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...
Aharon Robbins

2004-03-19, 8:23 pm

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\",\"Number"
>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"

^^^^^

>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
Will Ganz

2004-03-19, 8:23 pm

> 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 for
your input.

This is what worked:

C:\>awk "BEGIN { format = \"%-14s %s\n\"; printf format, \"Name\", \"Number
\"; printf format, \"----\", \"------\" } { printf format, $1, $2 }" BBS-
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!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com