Code Comments
Programming Forum and web based access to our favorite programming groups.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!
Post Follow-up to this messageIn 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...
Post Follow-up to this messageIn 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
Post Follow-up to this message> 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!
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.