gawk-doc: example doesn't match actual output

Bug #287948 reported by Peter Cordes
6
Affects Status Importance Assigned to Milestone
gawk
Confirmed
Undecided
auto-bug-gawk
gawk-doc (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: gawk-doc

in (gawk.info.gz)Records, this example is given:
$ echo | awk 'BEGIN { RS = "a" } ; { print NF }'
1

 But that's wrong: real results
peter@tesla:~$ echo | gawk 'BEGIN { RS = "a" } ; { print NF }'
0
peter@tesla:~$ echo | gawk --posix 'BEGIN { RS = "a" } ; { print NF }'
1

gawk 1:3.1.6.dfsg-0ubuntu1 on AMD64 pre-Intrepid.

I'm not sure what the best thing for the docs to say would be. I assume it's a bug in the docs, not in awk, but I'm not sure.

I'm still trying to figure out what the most concise way to read lines from stdin, and feed them in batches of e.g. 10 lines to the stdin of separate invocations of another command. Probably perl, since awk's RS mechanism doesn't seem to be flexible enough. (I can do it in a perl one-liner, but I was trying to shorten it, and awk's print | command looks useful.)

Revision history for this message
Jeroen Schot (schot) wrote :

I reported this bug to the bug-gawk mailing list: http://lists.gnu.org/archive/html/bug-gawk/2012-04/msg00022.html

Changed in gawk:
status: New → Confirmed
Changed in gawk-doc (Ubuntu):
status: New → Confirmed
Revision history for this message
Adrian Bunk (bunk) wrote :

This is fixed in 4.1.3-0.1 (in xenial and later), it now says:

   Using an alphabetic character such as 'u' for the record separator is
highly likely to produce strange results. Using an unusual character
such as '/' is more likely to produce correct behavior in the majority
of cases, but there are no guarantees. The moral is: Know Your Data.

   When using regular characters as the record separator, there is one
unusual case that occurs when 'gawk' is being fully POSIX-compliant
(*note Options::). Then, the following (extreme) pipeline prints a
surprising '1':

     $ echo | gawk --posix 'BEGIN { RS = "a" } ; { print NF }'
     -| 1

Changed in gawk-doc (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

  • auto-bug-gawk Edit

Bug watches keep track of this bug in other bug trackers.