[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] Potential errors in Manual 4.1

From: bamber ward
Subject: [bug-gawk] Potential errors in Manual 4.1
Date: Wed, 27 Aug 2014 14:11:53 +0100

gawk manual Edition 4.1 April 2014


Section 4.9.1

The program there seems to give the wrong result.

cat getline1.txt




horse /*comment*/more text


The output is :



horse ore text


I think what may be happening is that the _expression_:


counts the beginning character twice. Changing t+2 to t+3 seems to fix it, at least for

the input I have tested it on


typo page 120

'$1 ~/foo/ {print $2}' mail-list

/foo/ should be /li/


typo 7.4.9

In gawk, execution of nextfile causes additional things to happen: any ENDFILE rules

are executed except in the case as mentioned below( 'below' should be 'above')



I have gawk 4.0.1 on ubuntu 14.04

There may be a problem with this function or perhaps I have not understood something properly.

I note that the syntax error pertains to zerofilef.awk not zerofile.awk  so perhaps

 my formulation of zerofile() is wrong. However, to avoid using ARGV[Argind] I would need to know beforehand what this represented which rather defeats the whole point of using the function

I have mentioned this before but  this was  rejected.

cat zerofilef.awk

function zerofile(ARGV[Argind], Argind )


   print ARGIND,Argind, ARGV[Argind]





zerofile.awk was taken from the distribution and copied into the directory


~/gawk/code-> gawk -f zerofile.awk -f zerofilef.awk empty.txt nonempty.txt empty2.txt

gawk: zerofilef.awk:2: function zerofile(ARGV[Argind], Argind )

gawk: zerofilef.awk:2:                       ^ syntax error

gawk: zerofilef.awk:2: error: function `zerofile': can't use special variable `ARGV' as a function parameter


cat user_zerofile.awk



# user_zerofile.awk --- library file to process empty input files

# bit of a 'fudge'    


     BEGIN { Argind = 0 }


     ARGIND > Argind + 1 {

         zf=ARGV[Argind]  # added

         for (Argind++; Argind < ARGIND; Argind++)

             zerofile(zf, Argind) # different




     ARGIND != Argind { Argind = ARGIND }


     END {


         if (ARGIND > Argind)

            zf2=ARGV[Argind] # added

             for (Argind++; Argind <= ARGIND; Argind++)

                 zerofile(zf2, Argind) # different





cat user_zerofilef.awk


function zerofile(zf, Argind )


   print ARGIND,Argind, ARGV[Argind]




~/gawk/code-> gawk -f  user_zerofile.awk -f user_zerofilef.awk empty.txt nonempty.txt empty2.txt

2 1 empty.txt

3 3 empty2.txt




page 307

I am doing this in 4.0.1

the lines:


This tells us that gawk is now ready to execute line 67, which decides whether to give

the lines the special “field skipping” treatment indicated by the -f command-line option.

(Notice that we skipped from where we were before at line 64 to here, since the condition

if (fcount == 0 && charcount == 0) was false


'-f' is  incorrect( there is no such command line option  for uniq.awk);it should be -1. It would have been helpful to have shown this on the given command line 

Without it, the above condition is true and next  gives;

 return (last == $0)

Incidentally, I had to do one more n than the manual stated in dgawk before m,aline, cline were
I hope you find the above helpful
Best Wishes

reply via email to

[Prev in Thread] Current Thread [Next in Thread]