aboutsummaryrefslogtreecommitdiffstats
path: root/doc/gawk.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/gawk.texi')
-rw-r--r--doc/gawk.texi48
1 files changed, 40 insertions, 8 deletions
diff --git a/doc/gawk.texi b/doc/gawk.texi
index 5ffc5335..91d3d167 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -225,10 +225,7 @@
@ignore
Some comments on the layout for TeX.
-1. Use at least texinfo.tex 2014-01-30.15
-2. When using @docbook, if the last line is part of a paragraph, end
-it with a space and @c so that the lines won't run together. This is a
-quirk of the language / makeinfo, and isn't going to change.
+1. Use at least texinfo.tex 2016-02-05.07.
@end ignore
@c merge the function and variable indexes into the concept index
@@ -21999,6 +21996,36 @@ Because of this, you should not call it from an @code{ENDFILE} rule.
(This isn't necessary anyway, because @command{gawk} goes to the next
file as soon as an @code{ENDFILE} rule finishes!)
+You need to be careful calling @code{rewind()}. You can end up
+causing infinite recursion if you don't pay attenion. Here is an
+example use:
+
+@example
+$ @kbd{cat data}
+@print{} a
+@print{} b
+@print{} c
+@print{} d
+@print{} e
+
+$ cat @kbd{test.awk}
+@print{} FNR == 3 && ! rewound @{
+@print{} rewound = 1
+@print{} rewind()
+@print{} @}
+@print{}
+@print{} @{ print FILENAME, FNR, $0 @}
+
+$ @kbd{gawk -f rewind.awk -f test.awk data }
+@print{} data 1 a
+@print{} data 2 b
+@print{} data 1 a
+@print{} data 2 b
+@print{} data 3 c
+@print{} data 4 d
+@print{} data 5 e
+@end example
+
@node File Checking
@subsection Checking for Readable @value{DDF}s
@@ -23695,7 +23722,7 @@ BEGIN @{
" for delimiter\n", Optarg) > "/dev/stderr"
Optarg = substr(Optarg, 1, 1)
@}
- FS = Optarg
+ fs = FS = Optarg
OFS = FS
if (FS == " ") # defeat awk semantics
FS = "[ ]"
@@ -23717,7 +23744,12 @@ special care when the field delimiter is a space. Using
a single space (@code{@w{" "}}) for the value of @code{FS} is
incorrect---@command{awk} would separate fields with runs of spaces,
TABs, and/or newlines, and we want them to be separated with individual
-spaces. Also remember that after @code{getopt()} is through
+spaces.
+To this end, we save the original space character in the variable
+@code{fs} for later use; after setting @code{FS} to @code{"[ ]"} we can't
+use it directly to see if the field delimiter character is in the string.
+
+Also remember that after @code{getopt()} is through
(as described in @ref{Getopt Function}),
we have to
clear out all the elements of @code{ARGV} from 1 to @code{Optind},
@@ -23869,7 +23901,7 @@ written out between the fields:
@example
@c file eg/prog/cut.awk
@{
- if (by_fields && suppress && index($0, FS) == 0)
+ if (by_fields && suppress && index($0, fs) == 0)
next
for (i = 1; i <= nfields; i++) @{
@@ -24934,7 +24966,7 @@ BEGIN @{
if (! do_lines && ! do_words && ! do_chars)
do_lines = do_words = do_chars = 1
- print_total = (ARGC - i > 2)
+ print_total = (ARGC - i > 1)
@}
@c endfile
@end example