home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / gawk-2.15.5-diffs.lha / src / diffs / gawk-2.15.5.diffs
Text File  |  1994-07-12  |  502KB  |  12,599 lines

  1. diff -rc --new-file /src/baseline/gawk-2.15.5/Makefile.in gawk-2.15.5/Makefile.in
  2. *** /src/baseline/gawk-2.15.5/Makefile.in    Wed Dec 29 11:25:34 1993
  3. --- gawk-2.15.5/Makefile.in    Sun Jun 12 21:43:01 1994
  4. ***************
  5. *** 19,98 ****
  6.   # along with GAWK; see the file COPYING.  If not, write to
  7.   # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  8.   
  9. ! # User tunable macros -- CHANGE THESE IN Makefile.in RATHER THAN IN 
  10. ! # Makefile, OR configure WILL OVERWRITE YOUR CHANGES
  11.   
  12. ! prefix = /usr/local
  13.   exec_prefix = $(prefix)
  14. - binprefix =
  15. - manprefix =
  16.   
  17.   bindir = $(exec_prefix)/bin
  18.   libdir = $(exec_prefix)/lib
  19. ! mandir = $(prefix)/man/man1
  20. ! manext = .1
  21.   infodir = $(prefix)/info
  22.   
  23. ! #    The provided "configure" is used to turn a config file (samples in
  24. ! #    the "config" directory into commands to edit config.in into
  25. ! #    a suitable config.h and to edit Makefile.in into Makefile.
  26. ! #    To port GAWK, create an appropriate config file using the ones in
  27. ! #    the config directory as examples and using the comments in config.in
  28. ! #    as a guide.
  29. ! CC=         gcc -g
  30. ! ##MAKE_CC## CC = cc
  31. ! PROFILE=    #-pg
  32. ! DEBUG=        #-DMALLOCDEBUG #-DDEBUG #-DFUNC_TRACE #-DMPROF
  33. ! LINKSTATIC=    #-Bstatic
  34. ! WARN=        #-W -Wunused -Wimplicit -Wreturn-type -Wcomment    # for gcc only
  35. ! # Parser to use on grammar - any one of the following will work
  36. ! PARSER = bison -y
  37. ! #PARSER = yacc
  38. ! #PARSER = byacc
  39. ! # Set LIBS to any libraries that are machine specific
  40. ! LIBS =
  41. ! # Cray 2 running Unicos 5.0.7
  42. ! ##MAKE_LIBNET## LIBS = -lnet
  43. ! # Systems with alloca in /lib/libPW.a
  44. ! ##MAKE_ALLOCA_PW## LIBS = -lPW
  45. ! # ALLOCA - only needed if you use bison
  46. ! #    Set equal to alloca.o if your system is S5 and you don't have
  47. ! #    alloca. Uncomment one of the rules below to make alloca.o from
  48. ! #    either alloca.s or alloca.c.
  49. ! #    This should have already been done automatically by configure.
  50. ! #
  51. ! #    Some systems have alloca in libPW.a, so LIBS=-lPW may work, too.
  52. ! ##MAKE_ALLOCA_C## ALLOCA= alloca.o
  53. ! ##MAKE_ALLOCA_S## ALLOCA= alloca.o
  54. ! VFLAGS=
  55. ! # VMS POSIX, VAXC V3.2
  56. ! ##MAKE_VMS-Posix## VFLAGS = -UVMS -D__STDC__=0
  57.   
  58. ! # HP/Apollo running cc version 6.7 or earlier
  59. ! ##MAKE_Apollo## VFLAGS = -U__STDC__ -A run,sys5.3
  60. ! ##MAKE_Apollo## LIBS = -A sys,any
  61.   
  62. ! # SGI IRIX 4.0.5 cc flags
  63. ! ##MAKE_SGI## VFLAGS = -cckr
  64. ! ##MAKE_NeXT## VFLAGS = -DGFMT_WORKAROUND
  65. ! CFLAGS = -O
  66. ! FLAGS = -DGAWK -DHAVE_CONFIG_H $(VFLAGS) $(DEBUG) $(PROFILE) $(WARN)
  67. ! LDFLAGS = $(LINKSTATIC) $(PROFILE)
  68.   
  69.   .c.o:
  70. !     $(CC) $(CFLAGS) $(FLAGS) -c $<
  71.   
  72.   # object files
  73.   AWKOBJS = main.o eval.o builtin.o msg.o iop.o io.o field.o array.o \
  74. --- 19,66 ----
  75.   # along with GAWK; see the file COPYING.  If not, write to
  76.   # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  77.   
  78. ! #### Start of system configuration section. ####
  79.   
  80. ! VPATH = @srcdir@
  81. ! srcdir = @srcdir@
  82. ! # Common prefix for machine-independent installed files.
  83. ! prefix = /gnu
  84. ! # Common prefix for machine-dependent installed files.
  85.   exec_prefix = $(prefix)
  86.   
  87. + # Directory to install executables in.
  88.   bindir = $(exec_prefix)/bin
  89. + # Directory to install libraries in.
  90.   libdir = $(exec_prefix)/lib
  91. ! # Directory to install the Info files in.
  92.   infodir = $(prefix)/info
  93. + # Directory to install the man page in.
  94. + mandir = $(prefix)/man/man$(manext)
  95. + # Number to put on the man page filename.
  96. + manext = 1
  97. + # Program to install executables.
  98. + INSTALL_PROGRAM = @INSTALL_PROGRAM@
  99. + # Program to install data like man pages.
  100. + INSTALL_DATA = @INSTALL_DATA@
  101. + # Generic install program.
  102. + INSTALL = @INSTALL@
  103. + CC = @CC@
  104. + DEFS = @DEFS@
  105. + CFLAGS = @CFLAGS@
  106.   
  107. ! LDFLAGS = @LDFLAGS@
  108. ! LIBS = @LIBS@
  109.   
  110. ! YACC = @YACC@
  111.   
  112. ! #### End of system configuration section. ####
  113.   
  114. + # "-I." is needed to find config.h in the build directory.
  115.   .c.o:
  116. !     $(CC) -c -I. -I$(srcdir) $(DEFS) $(CFLAGS) $< $(OUTPUT_OPTION)
  117.   
  118.   # object files
  119.   AWKOBJS = main.o eval.o builtin.o msg.o iop.o io.o field.o array.o \
  120. ***************
  121. *** 137,142 ****
  122. --- 105,112 ----
  123.   # Release of gawk.  There can be no leading or trailing white space here!
  124.   REL=2.15
  125.   
  126. + all:    gawk
  127.   # rules to build gawk
  128.   gawk:    $(ALLOBJS) $(GNUOBJS) $(REOBJS)
  129.       $(CC) -o gawk $(LDFLAGS) $(ALLOBJS) $(GNUOBJS) $(REOBJS) -lm $(LIBS)
  130. ***************
  131. *** 150,172 ****
  132.   main.o:    patchlevel.h
  133.   
  134.   awktab.c:    awk.y
  135. !     $(PARSER) -v awk.y
  136. ! ##MAKE_VMS-Posix##     mv ytab.c awktab.c
  137. ! ##MAKE_VMS-Posix## dummy.awk_tab.target:
  138. !     sed '/^extern char .malloc(), .realloc();$$/d' y.tab.c >awktab.c
  139. !     rm y.tab.c
  140.   
  141.   awktab.o:    awk.h
  142.   
  143. ! config.h:    config.in
  144. !     @echo You must provide a config.h!
  145. !     @echo Run \"./configure\" to build it for known systems
  146. !     @echo or copy config.in to config.h and edit it.; exit 1
  147.   
  148.   install:    gawk gawk.info
  149. !     cp gawk $(bindir) && chmod 755 $(bindir)/gawk
  150. !     cp gawk.1 $(mandir)/gawk$(manext) && chmod 644 $(mandir)/gawk$(manext)
  151. !     cp gawk.info* $(infodir) && chmod 644 $(infodir)/gawk.info*
  152.   
  153.   uninstall:
  154.       rm -f $(bindir)/gawk $(mandir)/gawk$(manext) $(infodir)/gawk.info*
  155. --- 120,141 ----
  156.   main.o:    patchlevel.h
  157.   
  158.   awktab.c:    awk.y
  159. !     @echo "expect 40 shift/reduce conflicts"
  160. !     $(YACC) -v $(srcdir)/awk.y
  161. !     @sed '/extern char.*malloc/d' <y.tab.c >awktab.c
  162. !     @rm y.tab.c
  163.   
  164.   awktab.o:    awk.h
  165.   
  166. ! # On AmigaDOS, there is no "native awk", so install gawk as both
  167. ! # /bin/gawk and /bin/awk.
  168.   
  169.   install:    gawk gawk.info
  170. !     $(INSTALL_PROGRAM) gawk $(bindir)/awk
  171. !     $(INSTALL_PROGRAM) gawk $(bindir)/gawk
  172. !     $(INSTALL_DATA) $(srcdir)/gawk.1 $(mandir)/gawk$(manext)
  173. !     cd $(srcdir); for f in gawk.info*; \
  174. !     do $(INSTALL_DATA) $$f $(infodir)/$$f; done
  175.   
  176.   uninstall:
  177.       rm -f $(bindir)/gawk $(mandir)/gawk$(manext) $(infodir)/gawk.info*
  178. ***************
  179. *** 181,193 ****
  180.   # One of these rules should have already been selected by running configure.
  181.   
  182.   
  183. - ##MAKE_ALLOCA_S## alloca.o:    alloca.s
  184. - ##MAKE_ALLOCA_S##     /lib/cpp < alloca.s | sed '/^#/d' > t.s
  185. - ##MAKE_ALLOCA_S##     as t.s -o alloca.o
  186. - ##MAKE_ALLOCA_S##     rm t.s
  187. - ##MAKE_ALLOCA_C## alloca.o:    alloca.c
  188.   # auxiliary rules for release maintenance
  189.   lint:    $(ALLSRC)
  190.       lint -hcbax $(FLAGS) $(ALLSRC)
  191. --- 150,155 ----
  192. ***************
  193. *** 215,228 ****
  194.       rm -f $(ALLDOC) gawk.log config.h
  195.   
  196.   gawk.dvi:    gawk.texi
  197. !     cp support/texinfo.tex .
  198. !     tex gawk.texi; texindex gawk.??
  199. !     tex gawk.texi; texindex gawk.??
  200. !     tex gawk.texi
  201.       rm -f texinfo.tex
  202.   
  203.   gawk.info:    gawk.texi
  204. !     makeinfo gawk.texi
  205.   
  206.   dist:    $(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) $(COPIES) $(SUPPORT) distclean
  207.       -rm -rf gawk-$(REL)*
  208. --- 177,190 ----
  209.       rm -f $(ALLDOC) gawk.log config.h
  210.   
  211.   gawk.dvi:    gawk.texi
  212. !     cp $(srcdir)/support/texinfo.tex .
  213. !     tex $(srcdir)/gawk.texi; texindex gawk.??
  214. !     tex $(srcdir)/gawk.texi; texindex gawk.??
  215. !     tex $(srcdir)/gawk.texi
  216.       rm -f texinfo.tex
  217.   
  218.   gawk.info:    gawk.texi
  219. !     makeinfo $(srcdir)/gawk.texi
  220.   
  221.   dist:    $(AWKSRC) $(GNUSRC) $(DOCS) $(MISC) $(COPIES) $(SUPPORT) distclean
  222.       -rm -rf gawk-$(REL)*
  223. ***************
  224. *** 264,266 ****
  225. --- 226,242 ----
  226.   
  227.   check:    test
  228.   
  229. + Makefile:    config.status $(srcdir)/Makefile.in
  230. +         $(SHELL) config.status
  231. + config.h:    stamp-config ;
  232. + stamp-config:    config.status $(srcdir)/config.h.in
  233. +         $(SHELL) config.status
  234. +         touch stamp-config
  235. + configure:    configure.in
  236. +         autoconf $(ACFLAGS)
  237. + config.h.in:    configure.in
  238. +         autoheader $(ACFLAGS)
  239. diff -rc --new-file /src/baseline/gawk-2.15.5/Product-Info gawk-2.15.5/Product-Info
  240. *** /src/baseline/gawk-2.15.5/Product-Info    Thu Jan  1 00:00:00 1970
  241. --- gawk-2.15.5/Product-Info    Tue Jul 12 17:12:01 1994
  242. ***************
  243. *** 0 ****
  244. --- 1,31 ----
  245. + .name
  246. + gawk
  247. + .fullname
  248. + GNU awk, pattern scanning and processing language
  249. + .type
  250. + Programmer Tool
  251. + .short
  252. + Pattern scanning & processing.
  253. + .description
  254. + Gawk is the GNU Project's implementation of the AWK programming
  255. + language.  It conforms to the definition of the language in the POSIX
  256. + 1003.2 Command Language And Utilities Standard.  This version in turn
  257. + is based on the description in "The AWK Programming Language", by Aho,
  258. + Kernighan, and Weinberger, with the additional features defined in the
  259. + System V Release 4 version of UNIX awk.  Gawk also provides some
  260. + GNU-specific extensions.
  261. + The command line consists of options to gawk itself, the AWK program
  262. + text (if not supplied via the -f or --file options), and values to be
  263. + made available in the ARGC and ARGV pre-defined AWK variables.
  264. + .version
  265. + 2.15.5
  266. + .author
  267. + Paul Rubin
  268. + Jay Fenlason
  269. + .requirements
  270. + Amiga binary requires ixemul.library.
  271. + .distribution
  272. + GNU Public License
  273. + .described-by
  274. + Fred Fish (fnf@amigalib.com)
  275. diff -rc --new-file /src/baseline/gawk-2.15.5/README.amiga gawk-2.15.5/README.amiga
  276. *** /src/baseline/gawk-2.15.5/README.amiga    Tue Jun  1 15:22:31 1993
  277. --- gawk-2.15.5/README.amiga    Sun Jun 12 21:43:03 1994
  278. ***************
  279. *** 24,30 ****
  280.   Amiga under AmigaOS with gcc
  281.   DOPRNT_MISSING 1
  282.   ENVSEP ','
  283. ! DEFPATH  ".,/usr/local/lib"
  284.   HAVE_UNDERSCORE_SETJMP 1
  285.   SRANDOM_PROTO 1
  286.   STDC_HEADERS 1
  287. --- 24,30 ----
  288.   Amiga under AmigaOS with gcc
  289.   DOPRNT_MISSING 1
  290.   ENVSEP ','
  291. ! DEFPATH  ".,/gnu/lib"
  292.   HAVE_UNDERSCORE_SETJMP 1
  293.   SRANDOM_PROTO 1
  294.   STDC_HEADERS 1
  295. diff -rc --new-file /src/baseline/gawk-2.15.5/awk.h gawk-2.15.5/awk.h
  296. *** /src/baseline/gawk-2.15.5/awk.h    Wed May 11 22:28:46 1994
  297. --- gawk-2.15.5/awk.h    Sun Jun 12 21:43:07 1994
  298. ***************
  299. *** 67,74 ****
  300.   #define const
  301.   #endif
  302.   
  303. ! #ifndef SIGTYPE
  304. ! #define SIGTYPE    void
  305.   #endif
  306.   
  307.   #ifdef SIZE_T_MISSING
  308. --- 67,74 ----
  309.   #define const
  310.   #endif
  311.   
  312. ! #ifndef RETSIGTYPE
  313. ! #define RETSIGTYPE    void
  314.   #endif
  315.   
  316.   #ifdef SIZE_T_MISSING
  317. ***************
  318. *** 191,197 ****
  319.   #endif
  320.   
  321.   #ifndef DEFPATH
  322. ! #define DEFPATH    ".:/usr/local/lib/awk:/usr/lib/awk"
  323.   #endif
  324.   
  325.   #ifndef ENVSEP
  326. --- 191,197 ----
  327.   #endif
  328.   
  329.   #ifndef DEFPATH
  330. ! #define DEFPATH    ".:/local/lib/awk:/gnu/lib/awk"
  331.   #endif
  332.   
  333.   #ifndef ENVSEP
  334. ***************
  335. *** 723,729 ****
  336.   extern Regexp *mk_re_parse P((char *s, int ignorecase));
  337.   extern void load_environ P((void));
  338.   extern char *arg_assign P((char *arg));
  339. ! extern SIGTYPE catchsig P((int sig, int code));
  340.   /* msg.c */
  341.   extern void err P((const char *s, const char *emsg, va_list argp));
  342.   #if _MSC_VER == 510
  343. --- 723,729 ----
  344.   extern Regexp *mk_re_parse P((char *s, int ignorecase));
  345.   extern void load_environ P((void));
  346.   extern char *arg_assign P((char *arg));
  347. ! extern RETSIGTYPE catchsig P((int sig, int code));
  348.   /* msg.c */
  349.   extern void err P((const char *s, const char *emsg, va_list argp));
  350.   #if _MSC_VER == 510
  351. diff -rc --new-file /src/baseline/gawk-2.15.5/config/amigados gawk-2.15.5/config/amigados
  352. *** /src/baseline/gawk-2.15.5/config/amigados    Thu Jan  1 00:00:00 1970
  353. --- gawk-2.15.5/config/amigados    Sun Jun 12 21:43:23 1994
  354. ***************
  355. *** 0 ****
  356. --- 1,6 ----
  357. + Amiga under AmigaOS with gcc
  358. + ENVSEP ','
  359. + DEFPATH  ".,/gnu/lib"
  360. + HAVE_UNDERSCORE_SETJMP 1
  361. + SRANDOM_PROTO 1
  362. + STDC_HEADERS 1
  363. diff -rc --new-file /src/baseline/gawk-2.15.5/config.h.in gawk-2.15.5/config.h.in
  364. *** /src/baseline/gawk-2.15.5/config.h.in    Thu Jan  1 00:00:00 1970
  365. --- gawk-2.15.5/config.h.in    Sun Jun 12 21:43:26 1994
  366. ***************
  367. *** 0 ****
  368. --- 1,290 ----
  369. + /*
  370. +  * config.h -- configuration definitions for gawk.
  371. +  *
  372. +  * __SYSTEM__
  373. +  */
  374. + /* 
  375. +  * Copyright (C) 1991, 1992, 1993 the Free Software Foundation, Inc.
  376. +  * 
  377. +  * This file is part of GAWK, the GNU implementation of the
  378. +  * AWK Progamming Language.
  379. +  * 
  380. +  * GAWK is free software; you can redistribute it and/or modify
  381. +  * it under the terms of the GNU General Public License as published by
  382. +  * the Free Software Foundation; either version 2, or (at your option)
  383. +  * any later version.
  384. +  * 
  385. +  * GAWK is distributed in the hope that it will be useful,
  386. +  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  387. +  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  388. +  * GNU General Public License for more details.
  389. +  * 
  390. +  * You should have received a copy of the GNU General Public License
  391. +  * along with GAWK; see the file COPYING.  If not, write to
  392. +  * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  393. +  */
  394. + /*
  395. +  * This file isolates configuration dependencies for gnu awk.
  396. +  * You should know something about your system, perhaps by having
  397. +  * a manual handy, when you edit this file.  You should copy config.h-dist
  398. +  * to config.h, and edit config.h.  Do not modify config.h-dist, so that
  399. +  * it will be easy to apply any patches that may be distributed.
  400. +  *
  401. +  * The general idea is that systems conforming to the various standards
  402. +  * should need to do the least amount of changing.  Definining the various
  403. +  * items in ths file usually means that your system is missing that
  404. +  * particular feature.
  405. +  *
  406. +  * The order of preference in standard conformance is ANSI C, POSIX,
  407. +  * and the SVID.
  408. +  *
  409. +  * If you have no clue as to what's going on with your system, try
  410. +  * compiling gawk without editing this file and see what shows up
  411. +  * missing in the link stage.  From there, you can probably figure out
  412. +  * which defines to turn on.
  413. +  */
  414. + /**************************/
  415. + /* Miscellanious features */
  416. + /**************************/
  417. + /*
  418. +  * BLKSIZE_MISSING
  419. +  *
  420. +  * Check your /usr/include/sys/stat.h file.  If the stat structure
  421. +  * does not have a member named st_blksize, define this.  (This will
  422. +  * most likely be the case on most System V systems prior to V.4.)
  423. +  */
  424. + #undef BLKSIZE_MISSING
  425. + /*
  426. +  * RETSIGTYPE
  427. +  *
  428. +  * The return type of the routines passed to the signal function.
  429. +  * Modern systems use `void', older systems use `int'.
  430. +  * If left undefined, it will default to void.
  431. +  */
  432. + #undef RETSIGTYPE
  433. + /*
  434. +  * SIZE_T_MISSING
  435. +  *
  436. +  * If your system has no typedef for size_t, define this to get a default
  437. +  */
  438. + #undef SIZE_T_MISSING
  439. + /*
  440. +  * CHAR_UNSIGNED
  441. +  *
  442. +  * If your machine uses unsigned characters (IBM RT and RS/6000 and others)
  443. +  * then define this for use in regex.c
  444. +  */
  445. + #undef CHAR_UNSIGNED
  446. + /*
  447. +  * HAVE_UNDERSCORE_SETJMP
  448. +  *
  449. +  * Check in your /usr/include/setjmp.h file.  If there are routines
  450. +  * there named _setjmp and _longjmp, then you should define this.
  451. +  * Typically only systems derived from Berkeley Unix have this.
  452. +  */
  453. + #undef HAVE_UNDERSCORE_SETJMP
  454. + /***********************************************/
  455. + /* Missing library subroutines or system calls */
  456. + /***********************************************/
  457. + /*
  458. +  * MEMCMP_MISSING
  459. +  * MEMCPY_MISSING
  460. +  * MEMSET_MISSING
  461. +  *
  462. +  * These three routines are for manipulating blocks of memory. Most
  463. +  * likely they will either all three be present or all three be missing,
  464. +  * so they're grouped together.
  465. +  */
  466. + #undef MEMCMP_MISSING
  467. + #undef MEMCPY_MISSING
  468. + #undef MEMSET_MISSING
  469. + /*
  470. +  * RANDOM_MISSING
  471. +  *
  472. +  * Your system does not have the random(3) suite of random number
  473. +  * generating routines.  These are different than the old rand(3)
  474. +  * routines!
  475. +  */
  476. + #undef RANDOM_MISSING
  477. + /*
  478. +  * STRCASE_MISSING
  479. +  *
  480. +  * Your system does not have the strcasemp() and strncasecmp()
  481. +  * routines that originated in Berkeley Unix.
  482. +  */
  483. + #undef STRCASE_MISSING
  484. + /*
  485. +  * STRCHR_MISSING
  486. +  *
  487. +  * Your system does not have the strchr() and strrchr() functions.
  488. +  */
  489. + #undef STRCHR_MISSING
  490. + /*
  491. +  * STRERROR_MISSING
  492. +  *
  493. +  * Your system lacks the ANSI C strerror() routine for returning the
  494. +  * strings associated with errno values.
  495. +  */
  496. + #undef STRERROR_MISSING
  497. + /*
  498. +  * STRTOD_MISSING
  499. +  *
  500. +  * Your system does not have the strtod() routine for converting
  501. +  * strings to double precision floating point values.
  502. +  */
  503. + #undef STRTOD_MISSING
  504. + /*
  505. +  * STRFTIME_MISSING
  506. +  *
  507. +  * Your system lacks the ANSI C strftime() routine for formatting
  508. +  * broken down time values.
  509. +  */
  510. + #undef STRFTIME_MISSING
  511. + /*
  512. +  * TZSET_MISSING
  513. +  *
  514. +  * If you have a 4.2 BSD vintage system, then the strftime() routine
  515. +  * supplied in the missing directory won't be enough, because it relies on the
  516. +  * tzset() routine from System V / Posix.  Fortunately, there is an
  517. +  * emulation for tzset() too that should do the trick.  If you don't
  518. +  * have tzset(), define this.
  519. +  */
  520. + #undef TZSET_MISSING
  521. + /*
  522. +  * TZNAME_MISSING
  523. +  *
  524. +  * Some systems do not support the external variables tzname and daylight.
  525. +  * If this is the case *and* strftime() is missing, define this.
  526. +  */
  527. + #undef TZNAME_MISSING
  528. + /*
  529. +  * STDC_HEADERS
  530. +  *
  531. +  * If your system does have ANSI compliant header files that
  532. +  * provide prototypes for library routines, then define this.
  533. +  */
  534. + #undef STDC_HEADERS
  535. + /*
  536. +  * NO_TOKEN_PASTING
  537. +  *
  538. +  * If your compiler define's __STDC__ but does not support token
  539. +  * pasting (tok##tok), then define this.
  540. +  */
  541. + #undef NO_TOKEN_PASTING
  542. + /*****************************************************************/
  543. + /* Stuff related to the Standard I/O Library.             */
  544. + /*****************************************************************/
  545. + /* Much of this is (still, unfortunately) black magic in nature. */
  546. + /* You may have to use some or all of these together to get gawk */
  547. + /* to work correctly.                         */
  548. + /*****************************************************************/
  549. + /*
  550. +  * NON_STD_SPRINTF
  551. +  *
  552. +  * Look in your /usr/include/stdio.h file.  If the return type of the
  553. +  * sprintf() function is NOT `int', define this.
  554. +  */
  555. + #undef NON_STD_SPRINTF
  556. + /*
  557. +  * VPRINTF_MISSING
  558. +  *
  559. +  * Define this if your system lacks vprintf() and the other routines
  560. +  * that go with it.  This will trigger an attempt to use _doprnt().
  561. +  * If you don't have that, this attempt will fail and you are on your own.
  562. +  */
  563. + #undef VPRINTF_MISSING
  564. + /*
  565. +  * Casts from size_t to int and back.  These will become unnecessary
  566. +  * at some point in the future, but for now are required where the
  567. +  * two types are a different representation.
  568. +  */
  569. + #undef SZTC
  570. + #undef INTC
  571. + /*
  572. +  * SYSTEM_MISSING
  573. +  *
  574. +  * Define this if your library does not provide a system function
  575. +  * or you are not entirely happy with it and would rather use
  576. +  * a provided replacement (atari only).
  577. +  */
  578. + #undef SYSTEM_MISSING
  579. + /*
  580. +  * FMOD_MISSING
  581. +  *
  582. +  * Define this if your system lacks the fmod() function and modf() will
  583. +  * be used instead.
  584. +  */
  585. + #undef FMOD_MISSING
  586. + /*******************************/
  587. + /* Gawk configuration options. */
  588. + /*******************************/
  589. + /*
  590. +  * DEFPATH
  591. +  *
  592. +  * The default search path for the -f option of gawk.  It is used
  593. +  * if the AWKPATH environment variable is undefined.  The default
  594. +  * definition is provided here.  Most likely you should not change
  595. +  * this.
  596. +  */
  597. + #define DEFPATH    ".,/local/lib/awk,/gnu/lib/awk"        /* HACK - fnf */
  598. + #define ENVSEP    ','                    /* HACK - fnf */
  599. + /*
  600. +  * alloca already has a prototype defined - don't redefine it
  601. +  */
  602. + #undef ALLOCA_PROTO
  603. + /*
  604. +  * srandom already has a prototype defined - don't redefine it
  605. +  */
  606. + #undef SRANDOM_PROTO
  607. + /*
  608. +  * getpgrp() in sysvr4 and POSIX takes no argument
  609. +  */
  610. + #undef GETPGRP_NOARG
  611. + /*
  612. +  * define const to nothing if not __STDC__
  613. +  */
  614. + #ifndef __STDC__
  615. + #define const
  616. + #endif
  617. + /* If svr4 and not gcc */
  618. + #undef SVR4
  619. + #ifdef SVR4
  620. + #define __svr4__ 1
  621. + #endif
  622. diff -rc --new-file /src/baseline/gawk-2.15.5/config.in gawk-2.15.5/config.in
  623. *** /src/baseline/gawk-2.15.5/config.in    Sun May  1 18:20:10 1994
  624. --- gawk-2.15.5/config.in    Sun Jun 12 21:43:29 1994
  625. ***************
  626. *** 272,278 ****
  627.    * this.
  628.    */
  629.   
  630. ! /* #define DEFPATH    ".:/usr/lib/awk:/usr/local/lib/awk" */
  631.   /* #define ENVSEP    ':' */
  632.   
  633.   /*
  634. --- 272,278 ----
  635.    * this.
  636.    */
  637.   
  638. ! /* #define DEFPATH    ".:/local/lib/awk:/gnu/lib/awk" */
  639.   /* #define ENVSEP    ':' */
  640.   
  641.   /*
  642. diff -rc --new-file /src/baseline/gawk-2.15.5/configure gawk-2.15.5/configure
  643. *** /src/baseline/gawk-2.15.5/configure    Tue May 18 12:34:04 1993
  644. --- gawk-2.15.5/configure    Sun Jun 12 21:53:47 1994
  645. ***************
  646. *** 1,36 ****
  647. ! #! /bin/sh
  648. ! #
  649. ! # configure -- produce a config.h from a known configuration
  650.   
  651. ! case "$#" in
  652. ! 1)    ;;
  653. ! *)    echo "Usage:  $0 system_type" >&2
  654. !     echo "Known systems:  `cd config; echo ;ls -C`" >&2
  655. !     exit 2
  656. !     ;;
  657. ! esac
  658. ! if [ -f config/$1 ]; then
  659. !     sh ./mungeconf config/$1 config.in >config.h
  660. !     # echo #echo lines to stdout
  661. !     sed -n '/^#echo /s///p' config/$1
  662. !     case "$1" in
  663. !     bsd44)    ln -s Makefile.bsd44 Makefile ; exit 0 ;;
  664. !     esac
  665. !     sed -n '/^MAKE_.*/s//s,^##&## ,,/p' config/$1 >sedscr
  666. !     if [ -s sedscr ]
  667. !     then
  668. !         sed -f sedscr Makefile.in >Makefile
  669. !     else
  670. !         cp Makefile.in Makefile
  671.       fi
  672. !     rm -f sedscr
  673.   else
  674. !     echo "\`$1' is not a known configuration."
  675. !     echo "Either construct one based on the examples in the config directory,"
  676. !     echo "or copy config.in to config.h and edit it."
  677. !     exit 1
  678.   fi
  679. --- 1,899 ----
  680. ! #!/bin/sh
  681. ! # Guess values for system-dependent variables and create Makefiles.
  682. ! # Generated automatically using autoconf version 1.11 
  683. ! # Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
  684. ! # This configure script is free software; you can redistribute it and/or
  685. ! # modify it under the terms of the GNU General Public License as published
  686. ! # by the Free Software Foundation; either version 2, or (at your option)
  687. ! # any later version.
  688. ! # This script is distributed in the hope that it will be useful, but
  689. ! # WITHOUT ANY WARRANTY; without even the implied warranty of
  690. ! # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
  691. ! # Public License for more details.
  692. ! # You should have received a copy of the GNU General Public License
  693. ! # along with this program; if not, write to the Free Software
  694. ! # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  695. ! # Save the original args to write them into config.status later.
  696. ! configure_args="$*"
  697. ! # Only options that might do something get documented.
  698. ! ac_usage="Usage: configure [options] [host]
  699. ! Options: [defaults in brackets after descriptions]
  700. ! --build=BUILD        configure for building on BUILD [BUILD=HOST]
  701. ! --disable-FEATURE    do not include FEATURE (same as --enable-FEATURE=no)
  702. ! --enable-FEATURE[=ARG]    include FEATURE [ARG=yes]
  703. ! --exec-prefix=PREFIX    install host dependent files in PREFIX [/usr/local]
  704. ! --help            print this message
  705. ! --host=HOST        configure for HOST [guessed]
  706. ! --prefix=PREFIX        install host independent files in PREFIX [/usr/local]
  707. ! --quiet, --silent    do not print \`checking for...' messages
  708. ! --srcdir=DIR        find the sources in DIR [configure dir or ..]
  709. ! --target=TARGET        configure for TARGET [TARGET=HOST]
  710. ! --verbose        print results of checks
  711. ! --version        print the version of autoconf that created configure
  712. ! --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  713. ! --without-PACKAGE    do not use PACKAGE (same as --with-PACKAGE=no)
  714. ! --x-includes=DIR    X include files are in DIR
  715. ! --x-libraries=DIR    X library files are in DIR"
  716. ! # Initialize some variables set by options.
  717. ! # The variables have the same names as the options, with
  718. ! # dashes changed to underlines.
  719. ! build=NONE
  720. ! exec_prefix=
  721. ! host=NONE
  722. ! no_create=
  723. ! nonopt=NONE
  724. ! norecursion=
  725. ! prefix=
  726. ! program_prefix=
  727. ! program_suffix=
  728. ! program_transform_name=
  729. ! silent=
  730. ! srcdir=
  731. ! target=NONE
  732. ! verbose=
  733. ! x_includes=
  734. ! x_libraries=
  735. ! ac_prev=
  736. ! for ac_option
  737. ! do
  738. !   # If the previous option needs an argument, assign it.
  739. !   if test -n "$ac_prev"; then
  740. !     eval "$ac_prev=\$ac_option"
  741. !     ac_prev=
  742. !     continue
  743. !   fi
  744. !   # Accept (but ignore some of) the important Cygnus configure
  745. !   # options, so we can diagnose typos.
  746. !   case "$ac_option" in
  747. !   -*=*) ac_optarg=`/bin/echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  748. !   *) ac_optarg= ;;
  749. !   esac
  750. !   case "$ac_option" in
  751. !   -build | --build | --buil | --bui | --bu | --b)
  752. !     ac_prev=build ;;
  753. !   -build=* | --build=* | --buil=* | --bui=* | --bu=* | --b=*)
  754. !     build="$ac_optarg" ;;
  755. !   -disable-* | --disable-*)
  756. !     ac_feature=`/bin/echo $ac_option|sed -e 's/-*disable-//'`
  757. !     # Reject names that aren't valid shell variable names.
  758. !     if test -n "`/bin/echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
  759. !       /bin/echo "configure: $ac_feature: invalid feature name" >&2; exit 1
  760. !     fi
  761. !     ac_feature=`/bin/echo $ac_feature| sed 's/-/_/g'`
  762. !     eval "enable_${ac_feature}=no" ;;
  763. !   -enable-* | --enable-*)
  764. !     ac_feature=`/bin/echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
  765. !     # Reject names that aren't valid shell variable names.
  766. !     if test -n "`/bin/echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
  767. !       /bin/echo "configure: $ac_feature: invalid feature name" >&2; exit 1
  768. !     fi
  769. !     ac_feature=`/bin/echo $ac_feature| sed 's/-/_/g'`
  770. !     case "$ac_option" in
  771. !       *=*) ;;
  772. !       *) ac_optarg=yes ;;
  773. !     esac
  774. !     eval "enable_${ac_feature}='$ac_optarg'" ;;
  775. !   # For backward compatibility, recognize -exec-prefix and --exec_prefix.
  776. !   -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
  777. !   | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
  778. !   | --exec | --exe | --ex)
  779. !     ac_prev=exec_prefix ;;
  780. !   -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
  781. !   | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
  782. !   | --exec=* | --exe=* | --ex=*)
  783. !     exec_prefix="$ac_optarg" ;;
  784. !   -gas | --gas | --ga | --g)
  785. !     with_gas=yes ;; # Obsolete; use --with-gas.
  786. !   -help | --help | --hel | --he)
  787. !     cat << EOF
  788. ! $ac_usage
  789. ! EOF
  790. !     exit 0 ;;
  791. !   -host | --host | --hos | --ho)
  792. !     ac_prev=host ;;
  793. !   -host=* | --host=* | --hos=* | --ho=*)
  794. !     host="$ac_optarg" ;;
  795. !   -nfp | --nfp | --nf)
  796. !     with_fp=no ;; # Obsolete; use --without-fp.
  797. !   -no-create | --no-create | --no-creat | --no-crea | --no-cre \
  798. !   | --no-cr | --no-c)
  799. !     no_create=yes ;;
  800. !   -norecursion | --norecursion | --norecursio | --norecursi \
  801. !   | --norecurs | --norecur | --norecu | --norec | --nore | --nor)
  802. !     norecursion=yes ;;
  803. !   -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
  804. !     ac_prev=prefix ;;
  805. !   -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
  806. !     prefix="$ac_optarg" ;;
  807. !   -program-prefix | --program-prefix | --program-prefi | --program-pref \
  808. !   | --program-pre | --program-pr | --program-p)
  809. !     ac_prev=program_prefix ;;
  810. !   -program-prefix=* | --program-prefix=* | --program-prefi=* \
  811. !   | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
  812. !     program_prefix="$ac_optarg" ;;
  813. !   -program-suffix | --program-suffix | --program-suffi | --program-suff \
  814. !   | --program-suf | --program-su | --program-s)
  815. !     ac_prev=program_suffix ;;
  816. !   -program-suffix=* | --program-suffix=* | --program-suffi=* \
  817. !   | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
  818. !     program_suffix="$ac_optarg" ;;
  819. !   -program-transform-name | --program-transform-name \
  820. !   | --program-transform-nam | --program-transform-na \
  821. !   | --program-transform-n | --program-transform- \
  822. !   | --program-transform | --program-transfor \
  823. !   | --program-transfo | --program-transf \
  824. !   | --program-trans | --program-tran \
  825. !   | --progr-tra | --program-tr | --program-t)
  826. !     ac_prev=program_transform_name ;;
  827. !   -program-transform-name=* | --program-transform-name=* \
  828. !   | --program-transform-nam=* | --program-transform-na=* \
  829. !   | --program-transform-n=* | --program-transform-=* \
  830. !   | --program-transform=* | --program-transfor=* \
  831. !   | --program-transfo=* | --program-transf=* \
  832. !   | --program-trans=* | --program-tran=* \
  833. !   | --progr-tra=* | --program-tr=* | --program-t=*)
  834. !     program_transform_name="$ac_optarg" ;;
  835. !   -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  836. !   | -silent | --silent | --silen | --sile | --sil)
  837. !     silent=yes ;;
  838. !   -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
  839. !     ac_prev=srcdir ;;
  840. !   -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
  841. !     srcdir="$ac_optarg" ;;
  842. !   -target | --target | --targe | --targ | --tar | --ta | --t)
  843. !     ac_prev=target ;;
  844. !   -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
  845. !     target="$ac_optarg" ;;
  846. !   -v | -verbose | --verbose | --verbos | --verbo | --verb)
  847. !     verbose=yes ;;
  848. !   -version | --version | --versio | --versi | --vers)
  849. !     /bin/echo "configure generated by autoconf version 1.11"
  850. !     exit 0 ;;
  851. !   -with-* | --with-*)
  852. !     ac_package=`/bin/echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
  853. !     # Reject names that aren't valid shell variable names.
  854. !     if test -n "`/bin/echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
  855. !       /bin/echo "configure: $ac_package: invalid package name" >&2; exit 1
  856. !     fi
  857. !     ac_package=`/bin/echo $ac_package| sed 's/-/_/g'`
  858. !     case "$ac_option" in
  859. !       *=*) ;;
  860. !       *) ac_optarg=yes ;;
  861. !     esac
  862. !     eval "with_${ac_package}='$ac_optarg'" ;;
  863. !   -without-* | --without-*)
  864. !     ac_package=`/bin/echo $ac_option|sed -e 's/-*without-//'`
  865. !     # Reject names that aren't valid shell variable names.
  866. !     if test -n "`/bin/echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
  867. !       /bin/echo "configure: $ac_package: invalid package name" >&2; exit 1
  868. !     fi
  869. !     ac_package=`/bin/echo $ac_package| sed 's/-/_/g'`
  870. !     eval "with_${ac_package}=no" ;;
  871. !   --x) with_x=yes ;; # Obsolete; use --with-x.
  872. !   -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
  873. !   | --x-incl | --x-inc | --x-in | --x-i)
  874. !     ac_prev=x_includes ;;
  875. !   -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
  876. !   | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
  877. !     x_includes="$ac_optarg" ;;
  878. !   -x-libraries | --x-libraries | --x-librarie | --x-librari \
  879. !   | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
  880. !     ac_prev=x_libraries ;;
  881. !   -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
  882. !   | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
  883. !     x_libraries="$ac_optarg" ;;
  884. !   -*) /bin/echo "configure: $ac_option: invalid option; use --help to show usage" >&2; exit 1
  885. !     ;;
  886. !   *) 
  887. !     if test -n "`/bin/echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
  888. !       /bin/echo "configure: warning: $ac_option: invalid host type" >&2
  889. !     fi
  890. !     if test "x$nonopt" != xNONE; then
  891. !       /bin/echo "configure: can only configure for one host and one target at a time" >&2; exit 1
  892. !     fi
  893. !     nonopt="$ac_option"
  894. !     ;;
  895. !   esac
  896. ! done
  897. ! if test -n "$ac_prev"; then
  898. !   /bin/echo "configure: missing argument to --`/bin/echo $ac_prev | sed 's/_/-/g'`" >&2; exit 1
  899. ! fi
  900. ! trap 'rm -fr conftest* confdefs* core $ac_clean_files; exit 1' 1 2 15
  901. ! trap 'rm -fr confdefs* $ac_clean_files' 0
  902. ! # Save the original args if we used an alternate arg parser.
  903. ! ac_configure_temp="${configure_args-$*}"
  904. ! # Strip out --no-create and --norecursion so they don't pile up.
  905. ! configure_args=
  906. ! for ac_arg in $ac_configure_temp; do
  907. !   case "$ac_arg" in
  908. !   -no-create | --no-create | --no-creat | --no-crea | --no-cre \
  909. !   | --no-cr | --no-c) ;;
  910. !   -norecursion | --norecursion | --norecursio | --norecursi \
  911. !   | --norecurs | --norecur | --norecu | --norec | --nore | --nor) ;;
  912. !   *) configure_args="$configure_args $ac_arg" ;;
  913. !   esac
  914. ! done
  915. ! # NLS nuisances.
  916. ! # These must not be set unconditionally because not all systems understand
  917. ! # e.g. LANG=C (notably SCO).
  918. ! if test "${LC_ALL+set}" = 'set'; then LC_ALL=C; export LC_ALL; fi
  919. ! if test "${LANG+set}"   = 'set'; then LANG=C;   export LANG;   fi
  920. ! # confdefs.h avoids OS command line length limits that DEFS can exceed.
  921. ! rm -rf conftest* confdefs.h
  922. ! # AIX cpp loses on an empty file, so make sure it contains at least a newline.
  923. ! /bin/echo > confdefs.h
  924. ! # A filename unique to this package, relative to the directory that
  925. ! # configure is in, which we can look for to find out if srcdir is correct.
  926. ! ac_unique_file=awk.y
  927. ! # Find the source files, if location was not specified.
  928. ! if test -z "$srcdir"; then
  929. !   ac_srcdir_defaulted=yes
  930. !   # Try the directory containing this script, then `..'.
  931. !   ac_prog=$0
  932. !   ac_confdir=`/bin/echo $ac_prog|sed 's%/[^/][^/]*$%%'`
  933. !   test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
  934. !   srcdir=$ac_confdir
  935. !   if test ! -r $srcdir/$ac_unique_file; then
  936. !     srcdir=..
  937. !   fi
  938. ! fi
  939. ! if test ! -r $srcdir/$ac_unique_file; then
  940. !   if test x$ac_srcdir_defaulted = xyes; then
  941. !     /bin/echo "configure: can not find sources in ${ac_confdir} or .." >&2; exit 1
  942. !   else
  943. !     /bin/echo "configure: can not find sources in ${srcdir}" >&2; exit 1
  944. !   fi
  945. ! fi
  946. ! ac_ext=c
  947. ! # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
  948. ! ac_cpp='${CPP}'
  949. ! ac_compile='${CC-cc} $CFLAGS $LDFLAGS conftest.${ac_ext} -o conftest $LIBS >/dev/null 2>&1'
  950. ! # We want these before the checks, so the checks can modify their values.
  951. ! test -z "$CFLAGS" && CFLAGS= auto_cflags=1
  952. ! test -z "$LDFLAGS" && LDFLAGS=
  953. ! if test -z "$CC"; then
  954. !   # Extract the first word of `gcc', so it can be a program name with args.
  955. !   set ac_dummy gcc; ac_word=$2
  956. !   test -n "$silent" || /bin/echo "checking for $ac_word"
  957. !   IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  958. !   for ac_dir in $PATH; do
  959. !     test -z "$ac_dir" && ac_dir=.
  960. !     if test -f $ac_dir/$ac_word; then
  961. !       CC="gcc"
  962. !       break
  963. !     fi
  964. !   done
  965. !   IFS="$ac_save_ifs"
  966. ! fi
  967. ! test -z "$CC" && CC="cc"
  968. ! test -n "$CC" && test -n "$verbose" && /bin/echo "    setting CC to $CC"
  969. ! # Find out if we are using GNU C, under whatever name.
  970. ! cat > conftest.c <<EOF
  971. ! #ifdef __GNUC__
  972. !   yes
  973. ! #endif
  974. ! EOF
  975. ! ${CC-cc} -E conftest.c > conftest.out 2>&1
  976. ! if egrep yes conftest.out >/dev/null 2>&1; then
  977. !   GCC=1 # For later tests.
  978. ! fi
  979. ! rm -f conftest*
  980. ! # If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
  981. ! test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O2"
  982. ! test -n "$silent" || /bin/echo "checking how to run the C preprocessor"
  983. ! if test -z "$CPP"; then
  984. !   # This must be in double quotes, not single quotes, because CPP may get
  985. !   # substituted into the Makefile and ``${CC-cc}'' will simply confuse
  986. !   # make.  It must be expanded now.
  987. !   CPP="${CC-cc} -E"
  988. !   cat > conftest.${ac_ext} <<EOF
  989. ! #include "confdefs.h"
  990. ! #include <stdio.h>
  991. ! Syntax Error
  992. ! EOF
  993. ! # Some shells (Coherent) do redirections in the wrong order, so need
  994. ! # the parens.
  995. ! ac_err=`eval "($ac_cpp conftest.${ac_ext} >/dev/null) 2>&1"`
  996. ! if test -z "$ac_err"; then
  997. !   :
  998. ! else
  999. !   rm -rf conftest*
  1000. !   CPP="${CC-cc} -E -traditional-cpp"
  1001. !   cat > conftest.${ac_ext} <<EOF
  1002. ! #include "confdefs.h"
  1003. ! #include <stdio.h>
  1004. ! Syntax Error
  1005. ! EOF
  1006. ! # Some shells (Coherent) do redirections in the wrong order, so need
  1007. ! # the parens.
  1008. ! ac_err=`eval "($ac_cpp conftest.${ac_ext} >/dev/null) 2>&1"`
  1009. ! if test -z "$ac_err"; then
  1010. !   :
  1011. ! else
  1012. !   rm -rf conftest*
  1013. !   CPP=/lib/cpp
  1014. ! fi
  1015. ! rm -f conftest*
  1016. ! fi
  1017. ! rm -f conftest*
  1018. ! fi
  1019. ! test -n "$verbose" && /bin/echo "    setting CPP to $CPP"
  1020. ! if test -n "$GCC"; then
  1021. !   test -n "$silent" || /bin/echo "checking whether -traditional is needed"
  1022. !   ac_pattern="Autoconf.*'x'"
  1023. !   ac_prog='#include <sgtty.h>
  1024. ! Autoconf TIOCGETP'
  1025. !   cat > conftest.${ac_ext} <<EOF
  1026. ! #include "confdefs.h"
  1027. ! $ac_prog
  1028. ! EOF
  1029. ! eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1"
  1030. ! if egrep "$ac_pattern" conftest.out >/dev/null 2>&1; then
  1031. !   rm -rf conftest*
  1032. !   ac_need_trad=1
  1033. ! fi
  1034. ! rm -f conftest*
  1035.   
  1036. !   if test -z "$ac_need_trad"; then
  1037. !     ac_prog='#include <termio.h>
  1038. ! Autoconf TCGETA'
  1039. !     cat > conftest.${ac_ext} <<EOF
  1040. ! #include "confdefs.h"
  1041. ! $ac_prog
  1042. ! EOF
  1043. ! eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1"
  1044. ! if egrep "$ac_pattern" conftest.out >/dev/null 2>&1; then
  1045. !   rm -rf conftest*
  1046. !   ac_need_trad=1
  1047. ! fi
  1048. ! rm -f conftest*
  1049. !   fi
  1050. !   test -n "$ac_need_trad" && CC="$CC -traditional"
  1051. ! fi
  1052. ! # Make sure to not get the incompatible SysV /etc/install and
  1053. ! # /usr/sbin/install, which might be in PATH before a BSD-like install,
  1054. ! # or the SunOS /usr/etc/install directory, or the AIX /bin/install,
  1055. ! # or the AFS install, which mishandles nonexistent args, or
  1056. ! # /usr/ucb/install on SVR4, which tries to use the nonexistent group
  1057. ! # `staff', or /sbin/install on IRIX which has incompatible command-line
  1058. ! # syntax.  Sigh.
  1059. ! #
  1060. ! #     On most BSDish systems install is in /usr/bin, not /usr/ucb
  1061. ! #     anyway.
  1062. ! # This turns out not to be true, so the mere pathname isn't an indication
  1063. ! # of whether the program works.  What we really need is a set of tests for
  1064. ! # the install program to see if it actually works in all the required ways.
  1065. ! #
  1066. ! # Avoid using ./install, which might have been erroneously created
  1067. ! # by make from ./install.sh.
  1068. ! if test -z "${INSTALL}"; then
  1069. !   test -n "$silent" || /bin/echo "checking for a BSD compatible install"
  1070. !   IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  1071. !   for ac_dir in $PATH; do
  1072. !     case "$ac_dir" in
  1073. !     ''|.|/gnu/etc|/sbin|/usr/sbin|/usr/etc|/usr/afsws/bin|/usr/ucb) ;;
  1074. !     *)
  1075. !       # OSF1 and SCO ODT 3.0 have their own names for install.
  1076. !       for ac_prog in installbsd scoinst install; do
  1077. !         if test -f $ac_dir/$ac_prog; then
  1078. !       if test $ac_prog = install &&
  1079. !             grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
  1080. !         # AIX install.  It has an incompatible calling convention.
  1081. !         # OSF/1 installbsd also uses dspmsg, but is usable.
  1082. !         :
  1083. !       else
  1084. !         INSTALL="$ac_dir/$ac_prog -c"
  1085. !         break 2
  1086. !       fi
  1087.       fi
  1088. !       done
  1089. !       ;;
  1090. !     esac
  1091. !   done
  1092. !   IFS="$ac_save_ifs"
  1093. ! fi
  1094. ! if test -z "$INSTALL"; then
  1095. !   # As a last resort, use the slow shell script.
  1096. !   for ac_dir in ${srcdir} ${srcdir}/.. ${srcdir}/../..; do
  1097. !     if test -f $ac_dir/install.sh; then
  1098. !       INSTALL="$ac_dir/install.sh -c"; break
  1099. !     fi
  1100. !   done
  1101. ! fi
  1102. ! if test -z "$INSTALL"; then
  1103. !   /bin/echo "configure: can not find install.sh in ${srcdir} or ${srcdir}/.. or ${srcdir}/../.." >&2; exit 1
  1104. ! fi
  1105. ! test -n "$verbose" && /bin/echo "    setting INSTALL to $INSTALL"
  1106. ! # Use test -z because SunOS4 sh mishandles ${INSTALL_PROGRAM-'${INSTALL}'}.
  1107. ! # It thinks the first close brace ends the variable substitution.
  1108. ! test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
  1109. ! test -n "$verbose" && /bin/echo "    setting INSTALL_PROGRAM to $INSTALL_PROGRAM"
  1110. ! test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
  1111. ! test -n "$verbose" && /bin/echo "    setting INSTALL_DATA to $INSTALL_DATA"
  1112. ! for ac_prog in 'bison -y' byacc
  1113. ! do
  1114. ! if test -z "$YACC"; then
  1115. !   # Extract the first word of `$ac_prog', so it can be a program name with args.
  1116. !   set ac_dummy $ac_prog; ac_word=$2
  1117. !   test -n "$silent" || /bin/echo "checking for $ac_word"
  1118. !   IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
  1119. !   for ac_dir in $PATH; do
  1120. !     test -z "$ac_dir" && ac_dir=.
  1121. !     if test -f $ac_dir/$ac_word; then
  1122. !       YACC="$ac_prog"
  1123. !       break
  1124. !     fi
  1125. !   done
  1126. !   IFS="$ac_save_ifs"
  1127. ! fi
  1128. ! test -n "$YACC" && test -n "$verbose" && /bin/echo "    setting YACC to $YACC"
  1129. ! test -n "$YACC" && break
  1130. ! done
  1131. ! test -n "$YACC" || YACC="yacc"
  1132. ! test -n "$silent" || /bin/echo "checking for return type of signal handlers"
  1133. ! cat > conftest.${ac_ext} <<EOF
  1134. ! #include "confdefs.h"
  1135. ! #include <sys/types.h>
  1136. ! #include <signal.h>
  1137. ! #ifdef signal
  1138. ! #undef signal
  1139. ! #endif
  1140. ! extern void (*signal ()) ();
  1141. ! int main() { return 0; }
  1142. ! int t() { int i;; return 0; }
  1143. ! EOF
  1144. ! if eval $ac_compile; then
  1145. !   rm -rf conftest*
  1146. !   
  1147. ! {
  1148. ! test -n "$verbose" && \
  1149. ! /bin/echo "    defining" RETSIGTYPE to be "void"
  1150. ! /bin/echo "#define" RETSIGTYPE "void" >> confdefs.h
  1151. ! DEFS="$DEFS -DRETSIGTYPE=void"
  1152. ! ac_sed_defs="${ac_sed_defs}\${ac_dA}RETSIGTYPE\${ac_dB}RETSIGTYPE\${ac_dC}void\${ac_dD}
  1153. ! \${ac_uA}RETSIGTYPE\${ac_uB}RETSIGTYPE\${ac_uC}void\${ac_uD}
  1154. ! \${ac_eA}RETSIGTYPE\${ac_eB}RETSIGTYPE\${ac_eC}void\${ac_eD}
  1155. ! "
  1156. ! }
  1157. ! else
  1158. !   rm -rf conftest*
  1159. !   
  1160. ! {
  1161. ! test -n "$verbose" && \
  1162. ! /bin/echo "    defining" RETSIGTYPE to be "int"
  1163. ! /bin/echo "#define" RETSIGTYPE "int" >> confdefs.h
  1164. ! DEFS="$DEFS -DRETSIGTYPE=int"
  1165. ! ac_sed_defs="${ac_sed_defs}\${ac_dA}RETSIGTYPE\${ac_dB}RETSIGTYPE\${ac_dC}int\${ac_dD}
  1166. ! \${ac_uA}RETSIGTYPE\${ac_uB}RETSIGTYPE\${ac_uC}int\${ac_uD}
  1167. ! \${ac_eA}RETSIGTYPE\${ac_eB}RETSIGTYPE\${ac_eC}int\${ac_eD}
  1168. ! "
  1169. ! }
  1170. ! fi
  1171. ! rm -f conftest*
  1172. ! test -n "$silent" || /bin/echo "checking for ANSI C header files"
  1173. ! cat > conftest.${ac_ext} <<EOF
  1174. ! #include "confdefs.h"
  1175. ! #include <stdlib.h>
  1176. ! #include <stdarg.h>
  1177. ! #include <string.h>
  1178. ! #include <float.h>
  1179. ! EOF
  1180. ! # Some shells (Coherent) do redirections in the wrong order, so need
  1181. ! # the parens.
  1182. ! ac_err=`eval "($ac_cpp conftest.${ac_ext} >/dev/null) 2>&1"`
  1183. ! if test -z "$ac_err"; then
  1184. !   rm -rf conftest*
  1185. !   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  1186. ! /bin/echo '#include "confdefs.h"
  1187. ! #include <string.h>' > conftest.${ac_ext}
  1188. ! eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1"
  1189. ! if egrep "memchr" conftest.out >/dev/null 2>&1; then
  1190. !   rm -rf conftest*
  1191. !   # SGI's /bin/cc from Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
  1192. ! cat > conftest.${ac_ext} <<EOF
  1193. ! #include "confdefs.h"
  1194. ! #include <ctype.h>
  1195. ! #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
  1196. ! #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
  1197. ! #define XOR(e,f) (((e) && !(f)) || (!(e) && (f)))
  1198. ! int main () { int i; for (i = 0; i < 256; i++)
  1199. ! if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
  1200. ! exit (0); }
  1201. ! EOF
  1202. ! eval $ac_compile
  1203. ! if test -s conftest && (./conftest; exit) 2>/dev/null; then
  1204. !   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  1205. ! /bin/echo '#include "confdefs.h"
  1206. ! #include <stdlib.h>' > conftest.${ac_ext}
  1207. ! eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1"
  1208. ! if egrep "free" conftest.out >/dev/null 2>&1; then
  1209. !   rm -rf conftest*
  1210. !   
  1211. ! {
  1212. ! test -n "$verbose" && \
  1213. ! /bin/echo "    defining STDC_HEADERS"
  1214. ! /bin/echo "#define" STDC_HEADERS "1" >> confdefs.h
  1215. ! DEFS="$DEFS -DSTDC_HEADERS=1"
  1216. ! ac_sed_defs="${ac_sed_defs}\${ac_dA}STDC_HEADERS\${ac_dB}STDC_HEADERS\${ac_dC}1\${ac_dD}
  1217. ! \${ac_uA}STDC_HEADERS\${ac_uB}STDC_HEADERS\${ac_uC}1\${ac_uD}
  1218. ! \${ac_eA}STDC_HEADERS\${ac_eB}STDC_HEADERS\${ac_eC}1\${ac_eD}
  1219. ! "
  1220. ! }
  1221. ! fi
  1222. ! rm -f conftest*
  1223. ! fi
  1224. ! rm -fr conftest*
  1225. ! fi
  1226. ! rm -f conftest*
  1227. ! fi
  1228. ! rm -f conftest*
  1229. ! test -n "$silent" || /bin/echo "checking for _setjmp declaration in <setjmp.h>"
  1230. ! cat > conftest.${ac_ext} <<EOF
  1231. ! #include "confdefs.h"
  1232. ! #include <setjmp.h>
  1233. ! int main() { return 0; }
  1234. ! int t() { jmp_buf buf; _setjmp (buf); return 0; }
  1235. ! EOF
  1236. ! if eval $ac_compile; then
  1237. !   rm -rf conftest*
  1238. !   
  1239. ! {
  1240. ! test -n "$verbose" && \
  1241. ! /bin/echo "    defining HAVE_UNDERSCORE_SETJMP"
  1242. ! /bin/echo "#define" HAVE_UNDERSCORE_SETJMP "1" >> confdefs.h
  1243. ! DEFS="$DEFS -DHAVE_UNDERSCORE_SETJMP=1"
  1244. ! ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_UNDERSCORE_SETJMP\${ac_dB}HAVE_UNDERSCORE_SETJMP\${ac_dC}1\${ac_dD}
  1245. ! \${ac_uA}HAVE_UNDERSCORE_SETJMP\${ac_uB}HAVE_UNDERSCORE_SETJMP\${ac_uC}1\${ac_uD}
  1246. ! \${ac_eA}HAVE_UNDERSCORE_SETJMP\${ac_eB}HAVE_UNDERSCORE_SETJMP\${ac_eC}1\${ac_eD}
  1247. ! "
  1248. ! }
  1249. ! fi
  1250. ! rm -f conftest*
  1251. ! # The preferred way to propogate these variables is regular @ substitutions.
  1252. ! if test -n "$prefix"; then
  1253. !   ac_prsub="s%^prefix\\([     ]*\\)=\\([     ]*\\).*$%prefix\\1=\\2$prefix%"
  1254. ! else
  1255. !   prefix=/usr/local
  1256. ! fi
  1257. ! if test -n "$exec_prefix"; then
  1258. !   ac_prsub="$ac_prsub
  1259. ! s%^exec_prefix\\([     ]*\\)=\\([     ]*\\).*$%exec_prefix\\1=\\2$exec_prefix%"
  1260.   else
  1261. !   exec_prefix='${prefix}' # Let make expand it.
  1262. ! fi
  1263. ! # Any assignment to VPATH causes Sun make to only execute
  1264. ! # the first set of double-colon rules, so remove it if not needed.
  1265. ! # If there is a colon in the path, we need to keep it.
  1266. ! if test "x$srcdir" = x.; then
  1267. !   ac_vpsub='/^[     ]*VPATH[     ]*=[^:]*$/d'
  1268.   fi
  1269. + # Quote sed substitution magic chars in DEFS.
  1270. + cat >conftest.def <<EOF
  1271. + $DEFS
  1272. + EOF
  1273. + ac_escape_ampersand_and_backslash='s%[&\\]%\\&%g'
  1274. + DEFS=`sed "$ac_escape_ampersand_and_backslash" <conftest.def`
  1275. + rm -f conftest.def
  1276. + # Substitute for predefined variables.
  1277. + trap 'rm -f config.status; exit 1' 1 2 15
  1278. + /bin/echo creating config.status
  1279. + # Some systems, like AmigaDOS, won't allow you to remove a script that is
  1280. + # being executed, so just move it out of the way instead.
  1281. + if test -f config.status; then mv config.status config.status.old; else true; fi
  1282. + cat > config.status <<EOF
  1283. + #!/bin/sh
  1284. + # Generated automatically by configure.
  1285. + # Run this file to recreate the current configuration.
  1286. + # This directory was configured as follows,
  1287. + # on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
  1288. + #
  1289. + # $0 $configure_args
  1290. + ac_cs_usage="Usage: config.status [--recheck] [--version] [--help]"
  1291. + for ac_option
  1292. + do
  1293. +   case "\$ac_option" in
  1294. +   -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
  1295. +     /bin/echo running \${CONFIG_SHELL-/bin/sh} $0 $configure_args --no-create
  1296. +     exec \${CONFIG_SHELL-/bin/sh} $0 $configure_args --no-create ;;
  1297. +   -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
  1298. +     /bin/echo "config.status generated by autoconf version 1.11"
  1299. +     exit 0 ;;
  1300. +   -help | --help | --hel | --he | --h)
  1301. +     /bin/echo "\$ac_cs_usage"; exit 0 ;;
  1302. +   *) /bin/echo "\$ac_cs_usage"; exit 1 ;;
  1303. +   esac
  1304. + done
  1305. + trap 'rm -fr Makefile config.h conftest*; exit 1' 1 2 15
  1306. + CC='$CC'
  1307. + CFLAGS='$CFLAGS'
  1308. + LDFLAGS='$LDFLAGS'
  1309. + CPP='$CPP'
  1310. + INSTALL='$INSTALL'
  1311. + INSTALL_PROGRAM='$INSTALL_PROGRAM'
  1312. + INSTALL_DATA='$INSTALL_DATA'
  1313. + YACC='$YACC'
  1314. + LIBS='$LIBS'
  1315. + srcdir='$srcdir'
  1316. + top_srcdir='$top_srcdir'
  1317. + prefix='$prefix'
  1318. + exec_prefix='$exec_prefix'
  1319. + ac_prsub='$ac_prsub'
  1320. + ac_vpsub='$ac_vpsub'
  1321. + extrasub='$extrasub'
  1322. + EOF
  1323. + cat >> config.status <<\EOF
  1324. + ac_given_srcdir=$srcdir
  1325. + CONFIG_FILES=${CONFIG_FILES-"Makefile"}
  1326. + for ac_file in .. ${CONFIG_FILES}; do if test "x$ac_file" != x..; then
  1327. +   # Remove last slash and all that follows it.  Not all systems have dirname.
  1328. +   ac_dir=`/bin/echo $ac_file|sed 's%/[^/][^/]*$%%'`
  1329. +   if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
  1330. +     # The file is in a subdirectory.
  1331. +     test ! -d "$ac_dir" && mkdir "$ac_dir"
  1332. +     ac_dir_suffix="/$ac_dir"
  1333. +   else
  1334. +     ac_dir_suffix=
  1335. +   fi
  1336. +   # A "../" for each directory in $ac_dir_suffix.
  1337. +   ac_dots=`/bin/echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
  1338. +   case "$ac_given_srcdir" in
  1339. +   .)  srcdir=.
  1340. +       if test -z "$ac_dir_suffix"; then top_srcdir=.
  1341. +       else top_srcdir=`/bin/echo $ac_dots|sed 's%/$%%'`; fi ;;
  1342. +   /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
  1343. +   *) # Relative path.
  1344. +     srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
  1345. +     top_srcdir="$ac_dots$ac_given_srcdir" ;;
  1346. +   esac
  1347. +   /bin/echo creating "$ac_file"
  1348. +   rm -f "$ac_file"
  1349. +   comment_str="Generated automatically from `/bin/echo $ac_file|sed 's|.*/||'`.in by configure."
  1350. +   case "$ac_file" in
  1351. +     *.c | *.h | *.C | *.cc | *.m )  /bin/echo "/* $comment_str */" > "$ac_file" ;;
  1352. +     * )          /bin/echo "# $comment_str"     > "$ac_file" ;;
  1353. +   esac
  1354. +   sed -e "
  1355. + $ac_prsub
  1356. + $ac_vpsub
  1357. + $extrasub
  1358. + s%@CC@%$CC%g
  1359. + s%@CFLAGS@%$CFLAGS%g
  1360. + s%@LDFLAGS@%$LDFLAGS%g
  1361. + s%@CPP@%$CPP%g
  1362. + s%@INSTALL@%$INSTALL%g
  1363. + s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
  1364. + s%@INSTALL_DATA@%$INSTALL_DATA%g
  1365. + s%@YACC@%$YACC%g
  1366. + s%@LIBS@%$LIBS%g
  1367. + s%@srcdir@%$srcdir%g
  1368. + s%@top_srcdir@%$top_srcdir%g
  1369. + s%@prefix@%$prefix%g
  1370. + s%@exec_prefix@%$exec_prefix%g
  1371. + s%@DEFS@%-DHAVE_CONFIG_H%" $ac_given_srcdir/${ac_file}.in >> $ac_file
  1372. + fi; done
  1373. + # These sed commands are put into ac_sed_defs when defining a macro.
  1374. + # They are broken into pieces to make the sed script easier to manage.
  1375. + # They are passed to sed as "A NAME B NAME C VALUE D", where NAME
  1376. + # is the cpp macro being defined and VALUE is the value it is being given.
  1377. + # Each defining turns into a single global substitution command.
  1378. + # Hopefully no one uses "!" as a variable value.
  1379. + # Other candidates for the sed separators, like , and @, do get used.
  1380. + #
  1381. + # ac_d sets the value in "#define NAME VALUE" lines.
  1382. + ac_dA='s!^\([     ]*\)#\([     ]*define[     ][     ]*\)'
  1383. + ac_dB='\([     ][     ]*\)[^     ]*!\1#\2'
  1384. + ac_dC='\3'
  1385. + ac_dD='!g'
  1386. + # ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
  1387. + ac_uA='s!^\([     ]*\)#\([     ]*\)undef\([     ][     ]*\)'
  1388. + ac_uB='\([     ]\)!\1#\2define\3'
  1389. + ac_uC=' '
  1390. + ac_uD='\4!g'
  1391. + # ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
  1392. + ac_eA='s!^\([     ]*\)#\([     ]*\)undef\([     ][     ]*\)'
  1393. + ac_eB='$!\1#\2define\3'
  1394. + ac_eC=' '
  1395. + ac_eD='!g'
  1396. + rm -f conftest.sed
  1397. + EOF
  1398. + # Turn off quoting long enough to insert the sed commands.
  1399. + rm -f conftest.sh
  1400. + cat > conftest.sh <<EOF
  1401. + $ac_sed_defs
  1402. + EOF
  1403. + # Break up $ac_sed_defs (now in conftest.sh) because some shells have a limit
  1404. + # on the size of here documents.
  1405. + # Maximum number of lines to put in a single here document.
  1406. + ac_max_sh_lines=9
  1407. + while :
  1408. + do
  1409. +   # wc gives bogus results for an empty file on some AIX systems.
  1410. +   ac_lines=`grep -c . conftest.sh`
  1411. +   if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi
  1412. +   rm -f conftest.s1 conftest.s2
  1413. +   sed ${ac_max_sh_lines}q conftest.sh > conftest.s1 # Like head -9.
  1414. +   sed 1,${ac_max_sh_lines}d conftest.sh > conftest.s2 # Like tail +10.
  1415. +   # Write a limited-size here document to append to conftest.sed.
  1416. +   /bin/echo 'cat >> conftest.sed <<CONFEOF' >> config.status
  1417. +   cat conftest.s1 >> config.status
  1418. +   /bin/echo 'CONFEOF' >> config.status
  1419. +   rm -f conftest.s1 conftest.sh
  1420. +   mv conftest.s2 conftest.sh
  1421. + done
  1422. + rm -f conftest.sh
  1423. + # Now back to your regularly scheduled config.status.
  1424. + cat >> config.status <<\EOF
  1425. + # This sed command replaces #undef's with comments.  This is necessary, for
  1426. + # example, in the case of _POSIX_SOURCE, which is predefined and required
  1427. + # on some systems where configure will not decide to define it in
  1428. + # config.h.
  1429. + cat >> conftest.sed <<\CONFEOF
  1430. + s,^[     ]*#[     ]*undef[     ][     ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
  1431. + CONFEOF
  1432. + rm -f conftest.h
  1433. + # Break up the sed commands because old seds have small limits.
  1434. + ac_max_sed_lines=20
  1435. + CONFIG_HEADERS=${CONFIG_HEADERS-"config.h"}
  1436. + for ac_file in .. ${CONFIG_HEADERS}; do if test "x$ac_file" != x..; then
  1437. +   /bin/echo creating $ac_file
  1438. +   cp $ac_given_srcdir/$ac_file.in conftest.h1
  1439. +   cp conftest.sed conftest.stm
  1440. +   while :
  1441. +   do
  1442. +     ac_lines=`grep -c . conftest.stm`
  1443. +     if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi
  1444. +     rm -f conftest.s1 conftest.s2 conftest.h2
  1445. +     sed ${ac_max_sed_lines}q conftest.stm > conftest.s1 # Like head -20.
  1446. +     sed 1,${ac_max_sed_lines}d conftest.stm > conftest.s2 # Like tail +21.
  1447. +     sed -f conftest.s1 < conftest.h1 > conftest.h2
  1448. +     rm -f conftest.s1 conftest.h1 conftest.stm
  1449. +     mv conftest.h2 conftest.h1
  1450. +     mv conftest.s2 conftest.stm
  1451. +   done
  1452. +   rm -f conftest.stm conftest.h
  1453. +   /bin/echo "/* $ac_file.  Generated automatically by configure.  */" > conftest.h
  1454. +   cat conftest.h1 >> conftest.h
  1455. +   rm -f conftest.h1
  1456. +   if cmp -s $ac_file conftest.h 2>/dev/null; then
  1457. +     # The file exists and we would not be changing it.
  1458. +     /bin/echo "$ac_file is unchanged"
  1459. +     rm -f conftest.h
  1460. +   else
  1461. +     rm -f $ac_file
  1462. +     mv conftest.h $ac_file
  1463. +   fi
  1464. + fi; done
  1465. + rm -f conftest.sed
  1466. + exit 0
  1467. + EOF
  1468. + chmod +x config.status
  1469. + # Some shells look in PATH for config.status without the "./".
  1470. + test -n "$no_create" || ${CONFIG_SHELL-/bin/sh} ./config.status
  1471. diff -rc --new-file /src/baseline/gawk-2.15.5/configure.in gawk-2.15.5/configure.in
  1472. *** /src/baseline/gawk-2.15.5/configure.in    Thu Jan  1 00:00:00 1970
  1473. --- gawk-2.15.5/configure.in    Sun Jun 12 21:43:35 1994
  1474. ***************
  1475. *** 0 ****
  1476. --- 1,28 ----
  1477. + dnl Process this file with autoconf to produce a configure script.
  1478. + AC_INIT(awk.y)
  1479. + AC_CONFIG_HEADER(config.h)
  1480. + # We want these before the checks, so the checks can modify their values.
  1481. + test -z "$CFLAGS" && CFLAGS= auto_cflags=1
  1482. + test -z "$LDFLAGS" && LDFLAGS=
  1483. + AC_PROG_CC
  1484. + # If we're using gcc and the user hasn't specified CFLAGS, add -O to CFLAGS.
  1485. + test -n "$GCC" && test -n "$auto_cflags" && CFLAGS="$CFLAGS -O2"
  1486. + AC_SUBST(CFLAGS)dnl
  1487. + AC_SUBST(LDFLAGS)dnl
  1488. + AC_PROG_CPP
  1489. + AC_GCC_TRADITIONAL
  1490. + AC_PROG_INSTALL
  1491. + AC_PROG_YACC
  1492. + AC_RETSIGTYPE
  1493. + AC_STDC_HEADERS
  1494. + AC_COMPILE_CHECK(_setjmp declaration in <setjmp.h>,
  1495. +          [#include <setjmp.h>], [jmp_buf buf; _setjmp (buf)],
  1496. +          AC_DEFINE(HAVE_UNDERSCORE_SETJMP))
  1497. + AC_OUTPUT(Makefile)
  1498. diff -rc --new-file /src/baseline/gawk-2.15.5/dfa.h gawk-2.15.5/dfa.h
  1499. *** /src/baseline/gawk-2.15.5/dfa.h    Tue Jan  4 17:18:17 1994
  1500. --- gawk-2.15.5/dfa.h    Sun Jun 12 21:43:38 1994
  1501. ***************
  1502. *** 23,35 ****
  1503. --- 23,39 ----
  1504.      name space. */
  1505.   
  1506.   /* Number of bits in an unsigned char. */
  1507. + #ifndef CHARBITS
  1508.   #define CHARBITS 8
  1509. + #endif
  1510.   
  1511.   /* First integer value that is greater than any character code. */
  1512.   #define NOTCHAR (1 << CHARBITS)
  1513.   
  1514.   /* INTBITS need not be exact, just a lower bound. */
  1515. + #ifndef INTBITS
  1516.   #define INTBITS (CHARBITS * sizeof (int))
  1517. + #endif
  1518.   
  1519.   /* Number of ints required to hold a bit for every character. */
  1520.   #define CHARCLASS_INTS ((NOTCHAR + INTBITS - 1) / INTBITS)
  1521. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.1 gawk-2.15.5/gawk.1
  1522. *** /src/baseline/gawk-2.15.5/gawk.1    Mon Apr 18 18:04:03 1994
  1523. --- gawk-2.15.5/gawk.1    Sun Jun 12 21:43:43 1994
  1524. ***************
  1525. *** 329,335 ****
  1526.   the 
  1527.   .B \-f
  1528.   option.  If this variable does not exist, the default path is
  1529. ! \fB".:/usr/lib/awk:/usr/local/lib/awk"\fR.
  1530.   If a file name given to the
  1531.   .B \-f
  1532.   option contains a ``/'' character, no path search is performed.
  1533. --- 329,335 ----
  1534.   the 
  1535.   .B \-f
  1536.   option.  If this variable does not exist, the default path is
  1537. ! \fB".:/local/lib/awk:/gnu/lib/awk"\fR.
  1538.   If a file name given to the
  1539.   .B \-f
  1540.   option contains a ``/'' character, no path search is performed.
  1541. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info gawk-2.15.5/gawk.info
  1542. *** /src/baseline/gawk-2.15.5/gawk.info    Thu Jan  1 00:00:00 1970
  1543. --- gawk-2.15.5/gawk.info    Sun Jun 12 22:28:57 1994
  1544. ***************
  1545. *** 0 ****
  1546. --- 1,204 ----
  1547. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  1548. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  1549. +    This file documents `awk', a program that you can use to select
  1550. + particular records in a file and perform operations upon them.
  1551. +    This is Edition 0.15 of `The GAWK Manual',
  1552. + for the 2.15 version of the GNU implementation
  1553. + of AWK.
  1554. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  1555. +    Permission is granted to make and distribute verbatim copies of this
  1556. + manual provided the copyright notice and this permission notice are
  1557. + preserved on all copies.
  1558. +    Permission is granted to copy and distribute modified versions of
  1559. + this manual under the conditions for verbatim copying, provided that
  1560. + the entire resulting derived work is distributed under the terms of a
  1561. + permission notice identical to this one.
  1562. +    Permission is granted to copy and distribute translations of this
  1563. + manual into another language, under the above conditions for modified
  1564. + versions, except that this permission notice may be stated in a
  1565. + translation approved by the Foundation.
  1566. + 
  1567. + Indirect:
  1568. + gawk.info-1: 1079
  1569. + gawk.info-2: 48275
  1570. + gawk.info-3: 98104
  1571. + gawk.info-4: 146775
  1572. + gawk.info-5: 195898
  1573. + gawk.info-6: 243621
  1574. + gawk.info-7: 291484
  1575. + gawk.info-8: 340862
  1576. + gawk.info-9: 380695
  1577. + 
  1578. + Tag Table:
  1579. + (Indirect)
  1580. + Node: Top1079
  1581. + Node: Preface3990
  1582. + Node: History5583
  1583. + Node: Copying7926
  1584. + Node: This Manual27078
  1585. + Node: Sample Data Files28922
  1586. + Node: Getting Started31714
  1587. + Node: Very Simple33425
  1588. + Node: Two Rules35393
  1589. + Node: More Complex37477
  1590. + Node: Running gawk40463
  1591. + Node: One-shot41412
  1592. + Node: Read Terminal42548
  1593. + Node: Long43607
  1594. + Node: Executable Scripts44949
  1595. + Node: Comments47172
  1596. + Node: Statements/Lines48275
  1597. + Node: When51166
  1598. + Node: Reading Files53081
  1599. + Node: Records54808
  1600. + Node: Fields58042
  1601. + Node: Non-Constant Fields60655
  1602. + Node: Changing Fields62479
  1603. + Node: Field Separators65852
  1604. + Node: Constant Size75488
  1605. + Node: Multiple Line79036
  1606. + Node: Getline81432
  1607. + Node: Close Input91176
  1608. + Node: Printing92632
  1609. + Node: Print93631
  1610. + Node: Print Examples95765
  1611. + Node: Output Separators98104
  1612. + Node: OFMT99842
  1613. + Node: Printf100986
  1614. + Node: Basic Printf101890
  1615. + Node: Control Letters103315
  1616. + Node: Format Modifiers105129
  1617. + Node: Printf Examples107634
  1618. + Node: Redirection110316
  1619. + Node: File/Pipe Redirection111052
  1620. + Node: Close Output114525
  1621. + Node: Special Files117029
  1622. + Node: One-liners121963
  1623. + Node: Patterns124685
  1624. + Node: Kinds of Patterns125663
  1625. + Node: Regexp126668
  1626. + Node: Regexp Usage127612
  1627. + Node: Regexp Operators129641
  1628. + Node: Case-sensitivity135119
  1629. + Node: Comparison Patterns137429
  1630. + Node: Boolean Patterns139590
  1631. + Node: Expression Patterns141100
  1632. + Node: Ranges142540
  1633. + Node: BEGIN/END143950
  1634. + Node: Empty146504
  1635. + Node: Actions146775
  1636. + Node: Expressions149155
  1637. + Node: Constants151176
  1638. + Node: Variables156741
  1639. + Node: Assignment Options158350
  1640. + Node: Arithmetic Ops160034
  1641. + Node: Concatenation161700
  1642. + Node: Comparison Ops163048
  1643. + Node: Boolean Ops167473
  1644. + Node: Assignment Ops169936
  1645. + Node: Increment Ops174010
  1646. + Node: Conversion176506
  1647. + Node: Values179581
  1648. + Node: Conditional Exp182164
  1649. + Node: Function Calls183492
  1650. + Node: Precedence186256
  1651. + Node: Statements189639
  1652. + Node: If Statement191322
  1653. + Node: While Statement192850
  1654. + Node: Do Statement194813
  1655. + Node: For Statement195898
  1656. + Node: Break Statement199090
  1657. + Node: Continue Statement200699
  1658. + Node: Next Statement203322
  1659. + Node: Next File Statement205266
  1660. + Node: Exit Statement208312
  1661. + Node: Arrays209927
  1662. + Node: Array Intro211129
  1663. + Node: Reference to Elements214632
  1664. + Node: Assigning Elements216575
  1665. + Node: Array Example217077
  1666. + Node: Scanning an Array218808
  1667. + Node: Delete221108
  1668. + Node: Numeric Array Subscripts222088
  1669. + Node: Multi-dimensional223968
  1670. + Node: Multi-scanning227196
  1671. + Node: Built-in228818
  1672. + Node: Calling Built-in229775
  1673. + Node: Numeric Functions231039
  1674. + Node: String Functions234386
  1675. + Node: I/O Functions243621
  1676. + Node: Time Functions246245
  1677. + Node: User-defined254329
  1678. + Node: Definition Syntax255047
  1679. + Node: Function Example259039
  1680. + Node: Function Caveats260114
  1681. + Node: Return Statement263157
  1682. + Node: Built-in Variables265540
  1683. + Node: User-modified266576
  1684. + Node: Auto-set270853
  1685. + Node: Command Line276592
  1686. + Node: Options277517
  1687. + Node: Other Arguments284591
  1688. + Node: AWKPATH Variable286957
  1689. + Node: Obsolete289095
  1690. + Node: Undocumented290355
  1691. + Node: Language History290543
  1692. + Node: V7/S5R3.1291484
  1693. + Node: S5R4294188
  1694. + Node: POSIX295725
  1695. + Node: POSIX/GNU296443
  1696. + Node: Installation298074
  1697. + Node: Gawk Distribution298940
  1698. + Node: Extracting299393
  1699. + Node: Distribution contents300988
  1700. + Node: Unix Installation303792
  1701. + Node: Quick Installation304483
  1702. + Node: Configuration Philosophy305652
  1703. + Node: New Configurations307978
  1704. + Node: VMS Installation310080
  1705. + Node: VMS Compilation310639
  1706. + Node: VMS Installation Details312254
  1707. + Node: VMS Running313891
  1708. + Node: VMS POSIX315477
  1709. + Node: MS-DOS Installation316865
  1710. + Node: Atari Installation317793
  1711. + Node: Gawk Summary323555
  1712. + Node: Command Line Summary324316
  1713. + Node: Language Summary326749
  1714. + Node: Variables/Fields328834
  1715. + Node: Fields Summary329560
  1716. + Node: Built-in Summary331027
  1717. + Node: Arrays Summary334232
  1718. + Node: Data Type Summary335507
  1719. + Node: Rules Summary336980
  1720. + Node: Pattern Summary338629
  1721. + Node: Regexp Summary340862
  1722. + Node: Actions Summary342082
  1723. + Node: Operator Summary342997
  1724. + Node: Control Flow Summary344358
  1725. + Node: I/O Summary344964
  1726. + Node: Printf Summary346843
  1727. + Node: Special File Summary348669
  1728. + Node: Numeric Functions Summary350727
  1729. + Node: String Functions Summary351563
  1730. + Node: Time Functions Summary353395
  1731. + Node: String Constants Summary354159
  1732. + Node: Functions Summary355542
  1733. + Node: Historical Features356601
  1734. + Node: Sample Program357458
  1735. + Node: Bugs361712
  1736. + Node: Notes364560
  1737. + Node: Compatibility Mode365089
  1738. + Node: Future Extensions365922
  1739. + Node: Improvements368219
  1740. + Node: Glossary370254
  1741. + Node: Index380695
  1742. + 
  1743. + End Tag Table
  1744. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-1 gawk-2.15.5/gawk.info-1
  1745. *** /src/baseline/gawk-2.15.5/gawk.info-1    Thu Jan  1 00:00:00 1970
  1746. --- gawk-2.15.5/gawk.info-1    Sun Jun 12 22:28:48 1994
  1747. ***************
  1748. *** 0 ****
  1749. --- 1,1069 ----
  1750. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  1751. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  1752. +    This file documents `awk', a program that you can use to select
  1753. + particular records in a file and perform operations upon them.
  1754. +    This is Edition 0.15 of `The GAWK Manual',
  1755. + for the 2.15 version of the GNU implementation
  1756. + of AWK.
  1757. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  1758. +    Permission is granted to make and distribute verbatim copies of this
  1759. + manual provided the copyright notice and this permission notice are
  1760. + preserved on all copies.
  1761. +    Permission is granted to copy and distribute modified versions of
  1762. + this manual under the conditions for verbatim copying, provided that
  1763. + the entire resulting derived work is distributed under the terms of a
  1764. + permission notice identical to this one.
  1765. +    Permission is granted to copy and distribute translations of this
  1766. + manual into another language, under the above conditions for modified
  1767. + versions, except that this permission notice may be stated in a
  1768. + translation approved by the Foundation.
  1769. + 
  1770. + File: gawk.info,  Node: Top,  Next: Preface,  Prev: (dir),  Up: (dir)
  1771. + General Introduction
  1772. + ********************
  1773. +    This file documents `awk', a program that you can use to select
  1774. + particular records in a file and perform operations upon them.
  1775. +    This is Edition 0.15 of `The GAWK Manual',
  1776. + for the 2.15 version of the GNU implementation
  1777. + of AWK.
  1778. + * Menu:
  1779. + * Preface::                     What you can do with `awk'; brief history
  1780. +                                 and acknowledgements.
  1781. + * Copying::                     Your right to copy and distribute `gawk'.
  1782. + * This Manual::                 Using this manual.
  1783. +                                 Includes sample input files that you can use.
  1784. + * Getting Started::             A basic introduction to using `awk'.
  1785. +                                 How to run an `awk' program.
  1786. +                                 Command line syntax.
  1787. + * Reading Files::               How to read files and manipulate fields.
  1788. + * Printing::                    How to print using `awk'.  Describes the
  1789. +                                 `print' and `printf' statements.
  1790. +                                 Also describes redirection of output.
  1791. + * One-liners::                  Short, sample `awk' programs.
  1792. + * Patterns::                    The various types of patterns
  1793. +                                 explained in detail.
  1794. + * Actions::                     The various types of actions are
  1795. +                                 introduced here.  Describes
  1796. +                                 expressions and the various operators in
  1797. +                                 detail.  Also describes comparison expressions.
  1798. + * Expressions::                 Expressions are the basic building
  1799. +                                 blocks of statements.
  1800. + * Statements::                  The various control statements are
  1801. +                                 described in detail.
  1802. + * Arrays::                      The description and use of arrays.
  1803. +                                 Also includes array-oriented control
  1804. +                                 statements.
  1805. + * Built-in::                    The built-in functions are summarized here.
  1806. + * User-defined::                User-defined functions are described in detail.
  1807. + * Built-in Variables::          Built-in Variables
  1808. + * Command Line::                How to run `gawk'.
  1809. + * Language History::            The evolution of the `awk' language.
  1810. + * Installation::                Installing `gawk' under
  1811. +                                 various operating systems.
  1812. + * Gawk Summary::                `gawk' Options and Language Summary.
  1813. + * Sample Program::              A sample `awk' program with a
  1814. +                                 complete explanation.
  1815. + * Bugs::                        Reporting Problems and Bugs.
  1816. + * Notes::                       Something about the
  1817. +                                 implementation of `gawk'.
  1818. + * Glossary::                    An explanation of some unfamiliar terms.
  1819. + * Index::
  1820. + 
  1821. + File: gawk.info,  Node: Preface,  Next: Copying,  Prev: Top,  Up: Top
  1822. + Preface
  1823. + *******
  1824. +    If you are like many computer users, you would frequently like to
  1825. + make changes in various text files wherever certain patterns appear, or
  1826. + extract data from parts of certain lines while discarding the rest.  To
  1827. + write a program to do this in a language such as C or Pascal is a
  1828. + time-consuming inconvenience that may take many lines of code.  The job
  1829. + may be easier with `awk'.
  1830. +    The `awk' utility interprets a special-purpose programming language
  1831. + that makes it possible to handle simple data-reformatting jobs easily
  1832. + with just a few lines of code.
  1833. +    The GNU implementation of `awk' is called `gawk'; it is fully upward
  1834. + compatible with the System V Release 4 version of `awk'.  `gawk' is
  1835. + also upward compatible with the POSIX (draft) specification of the
  1836. + `awk' language.  This means that all properly written `awk' programs
  1837. + should work with `gawk'.  Thus, we usually don't distinguish between
  1838. + `gawk' and other `awk' implementations in this manual.
  1839. +    This manual teaches you what `awk' does and how you can use `awk'
  1840. + effectively.  You should already be familiar with basic system commands
  1841. + such as `ls'.  Using `awk' you can:
  1842. +    * manage small, personal databases
  1843. +    * generate reports
  1844. +    * validate data
  1845. +    * produce indexes, and perform other document preparation tasks
  1846. +    * even experiment with algorithms that can be adapted later to other
  1847. +      computer languages
  1848. + * Menu:
  1849. + * History::                     The history of `gawk' and
  1850. +                                 `awk'.  Acknowledgements.
  1851. + 
  1852. + File: gawk.info,  Node: History,  Prev: Preface,  Up: Preface
  1853. + History of `awk' and `gawk'
  1854. + ===========================
  1855. +    The name `awk' comes from the initials of its designers: Alfred V.
  1856. + Aho, Peter J. Weinberger, and Brian W. Kernighan.  The original version
  1857. + of `awk' was written in 1977.  In 1985 a new version made the
  1858. + programming language more powerful, introducing user-defined functions,
  1859. + multiple input streams, and computed regular expressions.  This new
  1860. + version became generally available with System V Release 3.1.  The
  1861. + version in System V Release 4 added some new features and also cleaned
  1862. + up the behavior in some of the "dark corners" of the language.  The
  1863. + specification for `awk' in the POSIX Command Language and Utilities
  1864. + standard further clarified the language based on feedback from both the
  1865. + `gawk' designers, and the original `awk' designers.
  1866. +    The GNU implementation, `gawk', was written in 1986 by Paul Rubin
  1867. + and Jay Fenlason, with advice from Richard Stallman.  John Woods
  1868. + contributed parts of the code as well.  In 1988 and 1989, David
  1869. + Trueman, with help from Arnold Robbins, thoroughly reworked `gawk' for
  1870. + compatibility with the newer `awk'.  Current development (1992) focuses
  1871. + on bug fixes, performance improvements, and standards compliance.
  1872. +    We need to thank many people for their assistance in producing this
  1873. + manual.  Jay Fenlason contributed many ideas and sample programs.
  1874. + Richard Mlynarik and Robert J. Chassell gave helpful comments on early
  1875. + drafts of this manual.  The paper `A Supplemental Document for `awk''
  1876. + by John W.  Pierce of the Chemistry Department at UC San Diego,
  1877. + pinpointed several issues relevant both to `awk' implementation and to
  1878. + this manual, that would otherwise have escaped us.  David Trueman, Pat
  1879. + Rankin, and Michal Jaegermann also contributed sections of the manual.
  1880. +    The following people provided many helpful comments on this edition
  1881. + of the manual: Rick Adams, Michael Brennan, Rich Burridge, Diane Close,
  1882. + Christopher ("Topher") Eliot, Michael Lijewski, Pat Rankin, Miriam
  1883. + Robbins, and Michal Jaegermann.  Robert J. Chassell provided much
  1884. + valuable advice on the use of Texinfo.
  1885. +    Finally, we would like to thank Brian Kernighan of Bell Labs for
  1886. + invaluable assistance during the testing and debugging of `gawk', and
  1887. + for help in clarifying numerous points about the language.
  1888. + 
  1889. + File: gawk.info,  Node: Copying,  Next: This Manual,  Prev: Preface,  Up: Top
  1890. + GNU GENERAL PUBLIC LICENSE
  1891. + **************************
  1892. +                          Version 2, June 1991
  1893. +      Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  1894. +      675 Mass Ave, Cambridge, MA 02139, USA
  1895. +      
  1896. +      Everyone is permitted to copy and distribute verbatim copies
  1897. +      of this license document, but changing it is not allowed.
  1898. + Preamble
  1899. + ========
  1900. +    The licenses for most software are designed to take away your
  1901. + freedom to share and change it.  By contrast, the GNU General Public
  1902. + License is intended to guarantee your freedom to share and change free
  1903. + software--to make sure the software is free for all its users.  This
  1904. + General Public License applies to most of the Free Software
  1905. + Foundation's software and to any other program whose authors commit to
  1906. + using it.  (Some other Free Software Foundation software is covered by
  1907. + the GNU Library General Public License instead.)  You can apply it to
  1908. + your programs, too.
  1909. +    When we speak of free software, we are referring to freedom, not
  1910. + price.  Our General Public Licenses are designed to make sure that you
  1911. + have the freedom to distribute copies of free software (and charge for
  1912. + this service if you wish), that you receive source code or can get it
  1913. + if you want it, that you can change the software or use pieces of it in
  1914. + new free programs; and that you know you can do these things.
  1915. +    To protect your rights, we need to make restrictions that forbid
  1916. + anyone to deny you these rights or to ask you to surrender the rights.
  1917. + These restrictions translate to certain responsibilities for you if you
  1918. + distribute copies of the software, or if you modify it.
  1919. +    For example, if you distribute copies of such a program, whether
  1920. + gratis or for a fee, you must give the recipients all the rights that
  1921. + you have.  You must make sure that they, too, receive or can get the
  1922. + source code.  And you must show them these terms so they know their
  1923. + rights.
  1924. +    We protect your rights with two steps: (1) copyright the software,
  1925. + and (2) offer you this license which gives you legal permission to copy,
  1926. + distribute and/or modify the software.
  1927. +    Also, for each author's protection and ours, we want to make certain
  1928. + that everyone understands that there is no warranty for this free
  1929. + software.  If the software is modified by someone else and passed on, we
  1930. + want its recipients to know that what they have is not the original, so
  1931. + that any problems introduced by others will not reflect on the original
  1932. + authors' reputations.
  1933. +    Finally, any free program is threatened constantly by software
  1934. + patents.  We wish to avoid the danger that redistributors of a free
  1935. + program will individually obtain patent licenses, in effect making the
  1936. + program proprietary.  To prevent this, we have made it clear that any
  1937. + patent must be licensed for everyone's free use or not licensed at all.
  1938. +    The precise terms and conditions for copying, distribution and
  1939. + modification follow.
  1940. +     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  1941. +   1. This License applies to any program or other work which contains a
  1942. +      notice placed by the copyright holder saying it may be distributed
  1943. +      under the terms of this General Public License.  The "Program",
  1944. +      below, refers to any such program or work, and a "work based on
  1945. +      the Program" means either the Program or any derivative work under
  1946. +      copyright law: that is to say, a work containing the Program or a
  1947. +      portion of it, either verbatim or with modifications and/or
  1948. +      translated into another language.  (Hereinafter, translation is
  1949. +      included without limitation in the term "modification".)  Each
  1950. +      licensee is addressed as "you".
  1951. +      Activities other than copying, distribution and modification are
  1952. +      not covered by this License; they are outside its scope.  The act
  1953. +      of running the Program is not restricted, and the output from the
  1954. +      Program is covered only if its contents constitute a work based on
  1955. +      the Program (independent of having been made by running the
  1956. +      Program).  Whether that is true depends on what the Program does.
  1957. +   2. You may copy and distribute verbatim copies of the Program's
  1958. +      source code as you receive it, in any medium, provided that you
  1959. +      conspicuously and appropriately publish on each copy an appropriate
  1960. +      copyright notice and disclaimer of warranty; keep intact all the
  1961. +      notices that refer to this License and to the absence of any
  1962. +      warranty; and give any other recipients of the Program a copy of
  1963. +      this License along with the Program.
  1964. +      You may charge a fee for the physical act of transferring a copy,
  1965. +      and you may at your option offer warranty protection in exchange
  1966. +      for a fee.
  1967. +   3. You may modify your copy or copies of the Program or any portion
  1968. +      of it, thus forming a work based on the Program, and copy and
  1969. +      distribute such modifications or work under the terms of Section 1
  1970. +      above, provided that you also meet all of these conditions:
  1971. +        a. You must cause the modified files to carry prominent notices
  1972. +           stating that you changed the files and the date of any change.
  1973. +        b. You must cause any work that you distribute or publish, that
  1974. +           in whole or in part contains or is derived from the Program
  1975. +           or any part thereof, to be licensed as a whole at no charge
  1976. +           to all third parties under the terms of this License.
  1977. +        c. If the modified program normally reads commands interactively
  1978. +           when run, you must cause it, when started running for such
  1979. +           interactive use in the most ordinary way, to print or display
  1980. +           an announcement including an appropriate copyright notice and
  1981. +           a notice that there is no warranty (or else, saying that you
  1982. +           provide a warranty) and that users may redistribute the
  1983. +           program under these conditions, and telling the user how to
  1984. +           view a copy of this License.  (Exception: if the Program
  1985. +           itself is interactive but does not normally print such an
  1986. +           announcement, your work based on the Program is not required
  1987. +           to print an announcement.)
  1988. +      These requirements apply to the modified work as a whole.  If
  1989. +      identifiable sections of that work are not derived from the
  1990. +      Program, and can be reasonably considered independent and separate
  1991. +      works in themselves, then this License, and its terms, do not
  1992. +      apply to those sections when you distribute them as separate
  1993. +      works.  But when you distribute the same sections as part of a
  1994. +      whole which is a work based on the Program, the distribution of
  1995. +      the whole must be on the terms of this License, whose permissions
  1996. +      for other licensees extend to the entire whole, and thus to each
  1997. +      and every part regardless of who wrote it.
  1998. +      Thus, it is not the intent of this section to claim rights or
  1999. +      contest your rights to work written entirely by you; rather, the
  2000. +      intent is to exercise the right to control the distribution of
  2001. +      derivative or collective works based on the Program.
  2002. +      In addition, mere aggregation of another work not based on the
  2003. +      Program with the Program (or with a work based on the Program) on
  2004. +      a volume of a storage or distribution medium does not bring the
  2005. +      other work under the scope of this License.
  2006. +   4. You may copy and distribute the Program (or a work based on it,
  2007. +      under Section 2) in object code or executable form under the terms
  2008. +      of Sections 1 and 2 above provided that you also do one of the
  2009. +      following:
  2010. +        a. Accompany it with the complete corresponding machine-readable
  2011. +           source code, which must be distributed under the terms of
  2012. +           Sections 1 and 2 above on a medium customarily used for
  2013. +           software interchange; or,
  2014. +        b. Accompany it with a written offer, valid for at least three
  2015. +           years, to give any third party, for a charge no more than your
  2016. +           cost of physically performing source distribution, a complete
  2017. +           machine-readable copy of the corresponding source code, to be
  2018. +           distributed under the terms of Sections 1 and 2 above on a
  2019. +           medium customarily used for software interchange; or,
  2020. +        c. Accompany it with the information you received as to the offer
  2021. +           to distribute corresponding source code.  (This alternative is
  2022. +           allowed only for noncommercial distribution and only if you
  2023. +           received the program in object code or executable form with
  2024. +           such an offer, in accord with Subsection b above.)
  2025. +      The source code for a work means the preferred form of the work for
  2026. +      making modifications to it.  For an executable work, complete
  2027. +      source code means all the source code for all modules it contains,
  2028. +      plus any associated interface definition files, plus the scripts
  2029. +      used to control compilation and installation of the executable.
  2030. +      However, as a special exception, the source code distributed need
  2031. +      not include anything that is normally distributed (in either
  2032. +      source or binary form) with the major components (compiler,
  2033. +      kernel, and so on) of the operating system on which the executable
  2034. +      runs, unless that component itself accompanies the executable.
  2035. +      If distribution of executable or object code is made by offering
  2036. +      access to copy from a designated place, then offering equivalent
  2037. +      access to copy the source code from the same place counts as
  2038. +      distribution of the source code, even though third parties are not
  2039. +      compelled to copy the source along with the object code.
  2040. +   5. You may not copy, modify, sublicense, or distribute the Program
  2041. +      except as expressly provided under this License.  Any attempt
  2042. +      otherwise to copy, modify, sublicense or distribute the Program is
  2043. +      void, and will automatically terminate your rights under this
  2044. +      License.  However, parties who have received copies, or rights,
  2045. +      from you under this License will not have their licenses
  2046. +      terminated so long as such parties remain in full compliance.
  2047. +   6. You are not required to accept this License, since you have not
  2048. +      signed it.  However, nothing else grants you permission to modify
  2049. +      or distribute the Program or its derivative works.  These actions
  2050. +      are prohibited by law if you do not accept this License.
  2051. +      Therefore, by modifying or distributing the Program (or any work
  2052. +      based on the Program), you indicate your acceptance of this
  2053. +      License to do so, and all its terms and conditions for copying,
  2054. +      distributing or modifying the Program or works based on it.
  2055. +   7. Each time you redistribute the Program (or any work based on the
  2056. +      Program), the recipient automatically receives a license from the
  2057. +      original licensor to copy, distribute or modify the Program
  2058. +      subject to these terms and conditions.  You may not impose any
  2059. +      further restrictions on the recipients' exercise of the rights
  2060. +      granted herein.  You are not responsible for enforcing compliance
  2061. +      by third parties to this License.
  2062. +   8. If, as a consequence of a court judgment or allegation of patent
  2063. +      infringement or for any other reason (not limited to patent
  2064. +      issues), conditions are imposed on you (whether by court order,
  2065. +      agreement or otherwise) that contradict the conditions of this
  2066. +      License, they do not excuse you from the conditions of this
  2067. +      License.  If you cannot distribute so as to satisfy simultaneously
  2068. +      your obligations under this License and any other pertinent
  2069. +      obligations, then as a consequence you may not distribute the
  2070. +      Program at all.  For example, if a patent license would not permit
  2071. +      royalty-free redistribution of the Program by all those who
  2072. +      receive copies directly or indirectly through you, then the only
  2073. +      way you could satisfy both it and this License would be to refrain
  2074. +      entirely from distribution of the Program.
  2075. +      If any portion of this section is held invalid or unenforceable
  2076. +      under any particular circumstance, the balance of the section is
  2077. +      intended to apply and the section as a whole is intended to apply
  2078. +      in other circumstances.
  2079. +      It is not the purpose of this section to induce you to infringe any
  2080. +      patents or other property right claims or to contest validity of
  2081. +      any such claims; this section has the sole purpose of protecting
  2082. +      the integrity of the free software distribution system, which is
  2083. +      implemented by public license practices.  Many people have made
  2084. +      generous contributions to the wide range of software distributed
  2085. +      through that system in reliance on consistent application of that
  2086. +      system; it is up to the author/donor to decide if he or she is
  2087. +      willing to distribute software through any other system and a
  2088. +      licensee cannot impose that choice.
  2089. +      This section is intended to make thoroughly clear what is believed
  2090. +      to be a consequence of the rest of this License.
  2091. +   9. If the distribution and/or use of the Program is restricted in
  2092. +      certain countries either by patents or by copyrighted interfaces,
  2093. +      the original copyright holder who places the Program under this
  2094. +      License may add an explicit geographical distribution limitation
  2095. +      excluding those countries, so that distribution is permitted only
  2096. +      in or among countries not thus excluded.  In such case, this
  2097. +      License incorporates the limitation as if written in the body of
  2098. +      this License.
  2099. +  10. The Free Software Foundation may publish revised and/or new
  2100. +      versions of the General Public License from time to time.  Such
  2101. +      new versions will be similar in spirit to the present version, but
  2102. +      may differ in detail to address new problems or concerns.
  2103. +      Each version is given a distinguishing version number.  If the
  2104. +      Program specifies a version number of this License which applies
  2105. +      to it and "any later version", you have the option of following
  2106. +      the terms and conditions either of that version or of any later
  2107. +      version published by the Free Software Foundation.  If the Program
  2108. +      does not specify a version number of this License, you may choose
  2109. +      any version ever published by the Free Software Foundation.
  2110. +  11. If you wish to incorporate parts of the Program into other free
  2111. +      programs whose distribution conditions are different, write to the
  2112. +      author to ask for permission.  For software which is copyrighted
  2113. +      by the Free Software Foundation, write to the Free Software
  2114. +      Foundation; we sometimes make exceptions for this.  Our decision
  2115. +      will be guided by the two goals of preserving the free status of
  2116. +      all derivatives of our free software and of promoting the sharing
  2117. +      and reuse of software generally.
  2118. +                                 NO WARRANTY
  2119. +  12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
  2120. +      WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
  2121. +      LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  2122. +      HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  2123. +      WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
  2124. +      NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2125. +      FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE
  2126. +      QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  2127. +      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  2128. +      SERVICING, REPAIR OR CORRECTION.
  2129. +  13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  2130. +      WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
  2131. +      MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
  2132. +      LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  2133. +      INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  2134. +      INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  2135. +      DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
  2136. +      OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
  2137. +      OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
  2138. +      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  2139. +                       END OF TERMS AND CONDITIONS
  2140. + How to Apply These Terms to Your New Programs
  2141. + =============================================
  2142. +    If you develop a new program, and you want it to be of the greatest
  2143. + possible use to the public, the best way to achieve this is to make it
  2144. + free software which everyone can redistribute and change under these
  2145. + terms.
  2146. +    To do so, attach the following notices to the program.  It is safest
  2147. + to attach them to the start of each source file to most effectively
  2148. + convey the exclusion of warranty; and each file should have at least
  2149. + the "copyright" line and a pointer to where the full notice is found.
  2150. +      ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
  2151. +      Copyright (C) 19YY  NAME OF AUTHOR
  2152. +      
  2153. +      This program is free software; you can redistribute it and/or modify
  2154. +      it under the terms of the GNU General Public License as published by
  2155. +      the Free Software Foundation; either version 2 of the License, or
  2156. +      (at your option) any later version.
  2157. +      
  2158. +      This program is distributed in the hope that it will be useful,
  2159. +      but WITHOUT ANY WARRANTY; without even the implied warranty of
  2160. +      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2161. +      GNU General Public License for more details.
  2162. +      
  2163. +      You should have received a copy of the GNU General Public License
  2164. +      along with this program; if not, write to the Free Software
  2165. +      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  2166. +    Also add information on how to contact you by electronic and paper
  2167. + mail.
  2168. +    If the program is interactive, make it output a short notice like
  2169. + this when it starts in an interactive mode:
  2170. +      Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
  2171. +      Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
  2172. +      type `show w'.
  2173. +      This is free software, and you are welcome to redistribute it
  2174. +      under certain conditions; type `show c' for details.
  2175. +    The hypothetical commands `show w' and `show c' should show the
  2176. + appropriate parts of the General Public License.  Of course, the
  2177. + commands you use may be called something other than `show w' and `show
  2178. + c'; they could even be mouse-clicks or menu items--whatever suits your
  2179. + program.
  2180. +    You should also get your employer (if you work as a programmer) or
  2181. + your school, if any, to sign a "copyright disclaimer" for the program,
  2182. + if necessary.  Here is a sample; alter the names:
  2183. +      Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  2184. +      `Gnomovision' (which makes passes at compilers) written by James Hacker.
  2185. +      
  2186. +      SIGNATURE OF TY COON, 1 April 1989
  2187. +      Ty Coon, President of Vice
  2188. +    This General Public License does not permit incorporating your
  2189. + program into proprietary programs.  If your program is a subroutine
  2190. + library, you may consider it more useful to permit linking proprietary
  2191. + applications with the library.  If this is what you want to do, use the
  2192. + GNU Library General Public License instead of this License.
  2193. + 
  2194. + File: gawk.info,  Node: This Manual,  Next: Getting Started,  Prev: Copying,  Up: Top
  2195. + Using this Manual
  2196. + *****************
  2197. +    The term `awk' refers to a particular program, and to the language
  2198. + you use to tell this program what to do.  When we need to be careful,
  2199. + we call the program "the `awk' utility" and the language "the `awk'
  2200. + language."  The term `gawk' refers to a version of `awk' developed as
  2201. + part the GNU project.  The purpose of this manual is to explain both the
  2202. + `awk' language and how to run the `awk' utility.
  2203. +    While concentrating on the features of `gawk', the manual will also
  2204. + attempt to describe important differences between `gawk' and other
  2205. + `awk' implementations.  In particular, any features that are not in the
  2206. + POSIX standard for `awk' will be noted.
  2207. +    The term "`awk' program" refers to a program written by you in the
  2208. + `awk' programming language.
  2209. +    *Note Getting Started with `awk': Getting Started, for the bare
  2210. + essentials you need to know to start using `awk'.
  2211. +    Some useful "one-liners" are included to give you a feel for the
  2212. + `awk' language (*note Useful "One-liners": One-liners.).
  2213. +    A sample `awk' program has been provided for you (*note Sample
  2214. + Program::.).
  2215. +    If you find terms that you aren't familiar with, try looking them up
  2216. + in the glossary (*note Glossary::.).
  2217. +    The entire `awk' language is summarized for quick reference in *Note
  2218. + `gawk' Summary: Gawk Summary.  Look there if you just need to refresh
  2219. + your memory about a particular feature.
  2220. +    Most of the time complete `awk' programs are used as examples, but in
  2221. + some of the more advanced sections, only the part of the `awk' program
  2222. + that illustrates the concept being described is shown.
  2223. + * Menu:
  2224. + * Sample Data Files::           Sample data files for use in the `awk'
  2225. +                                 programs illustrated in this manual.
  2226. + 
  2227. + File: gawk.info,  Node: Sample Data Files,  Prev: This Manual,  Up: This Manual
  2228. + Data Files for the Examples
  2229. + ===========================
  2230. +    Many of the examples in this manual take their input from two sample
  2231. + data files.  The first, called `BBS-list', represents a list of
  2232. + computer bulletin board systems together with information about those
  2233. + systems.  The second data file, called `inventory-shipped', contains
  2234. + information about shipments on a monthly basis.  Each line of these
  2235. + files is one "record".
  2236. +    In the file `BBS-list', each record contains the name of a computer
  2237. + bulletin board, its phone number, the board's baud rate, and a code for
  2238. + the number of hours it is operational.  An `A' in the last column means
  2239. + the board operates 24 hours a day.  A `B' in the last column means the
  2240. + board operates evening and weekend hours, only.  A `C' means the board
  2241. + operates only on weekends.
  2242. +      aardvark     555-5553     1200/300          B
  2243. +      alpo-net     555-3412     2400/1200/300     A
  2244. +      barfly       555-7685     1200/300          A
  2245. +      bites        555-1675     2400/1200/300     A
  2246. +      camelot      555-0542     300               C
  2247. +      core         555-2912     1200/300          C
  2248. +      fooey        555-1234     2400/1200/300     B
  2249. +      foot         555-6699     1200/300          B
  2250. +      macfoo       555-6480     1200/300          A
  2251. +      sdace        555-3430     2400/1200/300     A
  2252. +      sabafoo      555-2127     1200/300          C
  2253. +    The second data file, called `inventory-shipped', represents
  2254. + information about shipments during the year.  Each record contains the
  2255. + month of the year, the number of green crates shipped, the number of
  2256. + red boxes shipped, the number of orange bags shipped, and the number of
  2257. + blue packages shipped, respectively.  There are 16 entries, covering
  2258. + the 12 months of one year and 4 months of the next year.
  2259. +      Jan  13  25  15 115
  2260. +      Feb  15  32  24 226
  2261. +      Mar  15  24  34 228
  2262. +      Apr  31  52  63 420
  2263. +      May  16  34  29 208
  2264. +      Jun  31  42  75 492
  2265. +      Jul  24  34  67 436
  2266. +      Aug  15  34  47 316
  2267. +      Sep  13  55  37 277
  2268. +      Oct  29  54  68 525
  2269. +      Nov  20  87  82 577
  2270. +      Dec  17  35  61 401
  2271. +      
  2272. +      Jan  21  36  64 620
  2273. +      Feb  26  58  80 652
  2274. +      Mar  24  75  70 495
  2275. +      Apr  21  70  74 514
  2276. +    If you are reading this in GNU Emacs using Info, you can copy the
  2277. + regions of text showing these sample files into your own test files.
  2278. + This way you can try out the examples shown in the remainder of this
  2279. + document.  You do this by using the command `M-x write-region' to copy
  2280. + text from the Info file into a file for use with `awk' (*Note Misc File
  2281. + Ops: (emacs)Misc File Ops, for more information).  Using this
  2282. + information, create your own `BBS-list' and `inventory-shipped' files,
  2283. + and practice what you learn in this manual.
  2284. + 
  2285. + File: gawk.info,  Node: Getting Started,  Next: Reading Files,  Prev: This Manual,  Up: Top
  2286. + Getting Started with `awk'
  2287. + **************************
  2288. +    The basic function of `awk' is to search files for lines (or other
  2289. + units of text) that contain certain patterns.  When a line matches one
  2290. + of the patterns, `awk' performs specified actions on that line.  `awk'
  2291. + keeps processing input lines in this way until the end of the input
  2292. + file is reached.
  2293. +    When you run `awk', you specify an `awk' "program" which tells `awk'
  2294. + what to do.  The program consists of a series of "rules".  (It may also
  2295. + contain "function definitions", but that is an advanced feature, so we
  2296. + will ignore it for now.  *Note User-defined Functions: User-defined.)
  2297. + Each rule specifies one pattern to search for, and one action to
  2298. + perform when that pattern is found.
  2299. +    Syntactically, a rule consists of a pattern followed by an action.
  2300. + The action is enclosed in curly braces to separate it from the pattern.
  2301. + Rules are usually separated by newlines.  Therefore, an `awk' program
  2302. + looks like this:
  2303. +      PATTERN { ACTION }
  2304. +      PATTERN { ACTION }
  2305. +      ...
  2306. + * Menu:
  2307. + * Very Simple::                 A very simple example.
  2308. + * Two Rules::                   A less simple one-line example with two rules.
  2309. + * More Complex::                A more complex example.
  2310. + * Running gawk::                How to run `gawk' programs;
  2311. +                                 includes command line syntax.
  2312. + * Comments::                    Adding documentation to `gawk' programs.
  2313. + * Statements/Lines::            Subdividing or combining statements into lines.
  2314. + * When::                        When to use `gawk' and
  2315. +                                 when to use other things.
  2316. + 
  2317. + File: gawk.info,  Node: Very Simple,  Next: Two Rules,  Prev: Getting Started,  Up: Getting Started
  2318. + A Very Simple Example
  2319. + =====================
  2320. +    The following command runs a simple `awk' program that searches the
  2321. + input file `BBS-list' for the string of characters: `foo'.  (A string
  2322. + of characters is usually called, a "string".  The term "string" is
  2323. + perhaps based on similar usage in English, such as "a string of
  2324. + pearls," or, "a string of cars in a train.")
  2325. +      awk '/foo/ { print $0 }' BBS-list
  2326. + When lines containing `foo' are found, they are printed, because
  2327. + `print $0' means print the current line.  (Just `print' by itself means
  2328. + the same thing, so we could have written that instead.)
  2329. +    You will notice that slashes, `/', surround the string `foo' in the
  2330. + actual `awk' program.  The slashes indicate that `foo' is a pattern to
  2331. + search for.  This type of pattern is called a "regular expression", and
  2332. + is covered in more detail later (*note Regular Expressions as Patterns:
  2333. + Regexp.).  There are single-quotes around the `awk' program so that the
  2334. + shell won't interpret any of it as special shell characters.
  2335. +    Here is what this program prints:
  2336. +      fooey        555-1234     2400/1200/300     B
  2337. +      foot         555-6699     1200/300          B
  2338. +      macfoo       555-6480     1200/300          A
  2339. +      sabafoo      555-2127     1200/300          C
  2340. +    In an `awk' rule, either the pattern or the action can be omitted,
  2341. + but not both.  If the pattern is omitted, then the action is performed
  2342. + for *every* input line.  If the action is omitted, the default action
  2343. + is to print all lines that match the pattern.
  2344. +    Thus, we could leave out the action (the `print' statement and the
  2345. + curly braces) in the above example, and the result would be the same:
  2346. + all lines matching the pattern `foo' would be printed.  By comparison,
  2347. + omitting the `print' statement but retaining the curly braces makes an
  2348. + empty action that does nothing; then no lines would be printed.
  2349. + 
  2350. + File: gawk.info,  Node: Two Rules,  Next: More Complex,  Prev: Very Simple,  Up: Getting Started
  2351. + An Example with Two Rules
  2352. + =========================
  2353. +    The `awk' utility reads the input files one line at a time.  For
  2354. + each line, `awk' tries the patterns of each of the rules.  If several
  2355. + patterns match then several actions are run, in the order in which they
  2356. + appear in the `awk' program.  If no patterns match, then no actions are
  2357. + run.
  2358. +    After processing all the rules (perhaps none) that match the line,
  2359. + `awk' reads the next line (however, *note The `next' Statement: Next
  2360. + Statement.).  This continues until the end of the file is reached.
  2361. +    For example, the `awk' program:
  2362. +      /12/  { print $0 }
  2363. +      /21/  { print $0 }
  2364. + contains two rules.  The first rule has the string `12' as the pattern
  2365. + and `print $0' as the action.  The second rule has the string `21' as
  2366. + the pattern and also has `print $0' as the action.  Each rule's action
  2367. + is enclosed in its own pair of braces.
  2368. +    This `awk' program prints every line that contains the string `12'
  2369. + *or* the string `21'.  If a line contains both strings, it is printed
  2370. + twice, once by each rule.
  2371. +    If we run this program on our two sample data files, `BBS-list' and
  2372. + `inventory-shipped', as shown here:
  2373. +      awk '/12/ { print $0 }
  2374. +           /21/ { print $0 }' BBS-list inventory-shipped
  2375. + we get the following output:
  2376. +      aardvark     555-5553     1200/300          B
  2377. +      alpo-net     555-3412     2400/1200/300     A
  2378. +      barfly       555-7685     1200/300          A
  2379. +      bites        555-1675     2400/1200/300     A
  2380. +      core         555-2912     1200/300          C
  2381. +      fooey        555-1234     2400/1200/300     B
  2382. +      foot         555-6699     1200/300          B
  2383. +      macfoo       555-6480     1200/300          A
  2384. +      sdace        555-3430     2400/1200/300     A
  2385. +      sabafoo      555-2127     1200/300          C
  2386. +      sabafoo      555-2127     1200/300          C
  2387. +      Jan  21  36  64 620
  2388. +      Apr  21  70  74 514
  2389. + Note how the line in `BBS-list' beginning with `sabafoo' was printed
  2390. + twice, once for each rule.
  2391. + 
  2392. + File: gawk.info,  Node: More Complex,  Next: Running gawk,  Prev: Two Rules,  Up: Getting Started
  2393. + A More Complex Example
  2394. + ======================
  2395. +    Here is an example to give you an idea of what typical `awk'
  2396. + programs do.  This example shows how `awk' can be used to summarize,
  2397. + select, and rearrange the output of another utility.  It uses features
  2398. + that haven't been covered yet, so don't worry if you don't understand
  2399. + all the details.
  2400. +      ls -l | awk '$5 == "Nov" { sum += $4 }
  2401. +                   END { print sum }'
  2402. +    This command prints the total number of bytes in all the files in the
  2403. + current directory that were last modified in November (of any year).
  2404. + (In the C shell you would need to type a semicolon and then a backslash
  2405. + at the end of the first line; in a POSIX-compliant shell, such as the
  2406. + Bourne shell or the Bourne-Again shell, you can type the example as
  2407. + shown.)
  2408. +    The `ls -l' part of this example is a command that gives you a
  2409. + listing of the files in a directory, including file size and date.  Its
  2410. + output looks like this:
  2411. +      -rw-r--r--  1 close        1933 Nov  7 13:05 Makefile
  2412. +      -rw-r--r--  1 close       10809 Nov  7 13:03 gawk.h
  2413. +      -rw-r--r--  1 close         983 Apr 13 12:14 gawk.tab.h
  2414. +      -rw-r--r--  1 close       31869 Jun 15 12:20 gawk.y
  2415. +      -rw-r--r--  1 close       22414 Nov  7 13:03 gawk1.c
  2416. +      -rw-r--r--  1 close       37455 Nov  7 13:03 gawk2.c
  2417. +      -rw-r--r--  1 close       27511 Dec  9 13:07 gawk3.c
  2418. +      -rw-r--r--  1 close        7989 Nov  7 13:03 gawk4.c
  2419. + The first field contains read-write permissions, the second field
  2420. + contains the number of links to the file, and the third field
  2421. + identifies the owner of the file.  The fourth field contains the size
  2422. + of the file in bytes.  The fifth, sixth, and seventh fields contain the
  2423. + month, day, and time, respectively, that the file was last modified.
  2424. + Finally, the eighth field contains the name of the file.
  2425. +    The `$5 == "Nov"' in our `awk' program is an expression that tests
  2426. + whether the fifth field of the output from `ls -l' matches the string
  2427. + `Nov'.  Each time a line has the string `Nov' in its fifth field, the
  2428. + action `{ sum += $4 }' is performed.  This adds the fourth field (the
  2429. + file size) to the variable `sum'.  As a result, when `awk' has finished
  2430. + reading all the input lines, `sum' is the sum of the sizes of files
  2431. + whose lines matched the pattern.  (This works because `awk' variables
  2432. + are automatically initialized to zero.)
  2433. +    After the last line of output from `ls' has been processed, the
  2434. + `END' rule is executed, and the value of `sum' is printed.  In this
  2435. + example, the value of `sum' would be 80600.
  2436. +    These more advanced `awk' techniques are covered in later sections
  2437. + (*note Overview of Actions: Actions.).  Before you can move on to more
  2438. + advanced `awk' programming, you have to know how `awk' interprets your
  2439. + input and displays your output.  By manipulating fields and using
  2440. + `print' statements, you can produce some very useful and spectacular
  2441. + looking reports.
  2442. + 
  2443. + File: gawk.info,  Node: Running gawk,  Next: Comments,  Prev: More Complex,  Up: Getting Started
  2444. + How to Run `awk' Programs
  2445. + =========================
  2446. +    There are several ways to run an `awk' program.  If the program is
  2447. + short, it is easiest to include it in the command that runs `awk', like
  2448. + this:
  2449. +      awk 'PROGRAM' INPUT-FILE1 INPUT-FILE2 ...
  2450. + where PROGRAM consists of a series of patterns and actions, as
  2451. + described earlier.
  2452. +    When the program is long, it is usually more convenient to put it in
  2453. + a file and run it with a command like this:
  2454. +      awk -f PROGRAM-FILE INPUT-FILE1 INPUT-FILE2 ...
  2455. + * Menu:
  2456. + * One-shot::                    Running a short throw-away `awk' program.
  2457. + * Read Terminal::               Using no input files (input from
  2458. +                                 terminal instead).
  2459. + * Long::                        Putting permanent `awk' programs in files.
  2460. + * Executable Scripts::          Making self-contained `awk' programs.
  2461. + 
  2462. + File: gawk.info,  Node: One-shot,  Next: Read Terminal,  Prev: Running gawk,  Up: Running gawk
  2463. + One-shot Throw-away `awk' Programs
  2464. + ----------------------------------
  2465. +    Once you are familiar with `awk', you will often type simple
  2466. + programs at the moment you want to use them.  Then you can write the
  2467. + program as the first argument of the `awk' command, like this:
  2468. +      awk 'PROGRAM' INPUT-FILE1 INPUT-FILE2 ...
  2469. + where PROGRAM consists of a series of PATTERNS and ACTIONS, as
  2470. + described earlier.
  2471. +    This command format instructs the shell to start `awk' and use the
  2472. + PROGRAM to process records in the input file(s).  There are single
  2473. + quotes around PROGRAM so that the shell doesn't interpret any `awk'
  2474. + characters as special shell characters.  They also cause the shell to
  2475. + treat all of PROGRAM as a single argument for `awk' and allow PROGRAM
  2476. + to be more than one line long.
  2477. +    This format is also useful for running short or medium-sized `awk'
  2478. + programs from shell scripts, because it avoids the need for a separate
  2479. + file for the `awk' program.  A self-contained shell script is more
  2480. + reliable since there are no other files to misplace.
  2481. + 
  2482. + File: gawk.info,  Node: Read Terminal,  Next: Long,  Prev: One-shot,  Up: Running gawk
  2483. + Running `awk' without Input Files
  2484. + ---------------------------------
  2485. +    You can also run `awk' without any input files.  If you type the
  2486. + command line:
  2487. +      awk 'PROGRAM'
  2488. + then `awk' applies the PROGRAM to the "standard input", which usually
  2489. + means whatever you type on the terminal.  This continues until you
  2490. + indicate end-of-file by typing `Control-d'.
  2491. +    For example, if you execute this command:
  2492. +      awk '/th/'
  2493. + whatever you type next is taken as data for that `awk' program.  If you
  2494. + go on to type the following data:
  2495. +      Kathy
  2496. +      Ben
  2497. +      Tom
  2498. +      Beth
  2499. +      Seth
  2500. +      Karen
  2501. +      Thomas
  2502. +      `Control-d'
  2503. + then `awk' prints this output:
  2504. +      Kathy
  2505. +      Beth
  2506. +      Seth
  2507. + as matching the pattern `th'.  Notice that it did not recognize
  2508. + `Thomas' as matching the pattern.  The `awk' language is "case
  2509. + sensitive", and matches patterns exactly.  (However, you can override
  2510. + this with the variable `IGNORECASE'.  *Note Case-sensitivity in
  2511. + Matching: Case-sensitivity.)
  2512. + 
  2513. + File: gawk.info,  Node: Long,  Next: Executable Scripts,  Prev: Read Terminal,  Up: Running gawk
  2514. + Running Long Programs
  2515. + ---------------------
  2516. +    Sometimes your `awk' programs can be very long.  In this case it is
  2517. + more convenient to put the program into a separate file.  To tell `awk'
  2518. + to use that file for its program, you type:
  2519. +      awk -f SOURCE-FILE INPUT-FILE1 INPUT-FILE2 ...
  2520. +    The `-f' instructs the `awk' utility to get the `awk' program from
  2521. + the file SOURCE-FILE.  Any file name can be used for SOURCE-FILE.  For
  2522. + example, you could put the program:
  2523. +      /th/
  2524. + into the file `th-prog'.  Then this command:
  2525. +      awk -f th-prog
  2526. + does the same thing as this one:
  2527. +      awk '/th/'
  2528. + which was explained earlier (*note Running `awk' without Input Files:
  2529. + Read Terminal.).  Note that you don't usually need single quotes around
  2530. + the file name that you specify with `-f', because most file names don't
  2531. + contain any of the shell's special characters.  Notice that in
  2532. + `th-prog', the `awk' program did not have single quotes around it.  The
  2533. + quotes are only needed for programs that are provided on the `awk'
  2534. + command line.
  2535. +    If you want to identify your `awk' program files clearly as such,
  2536. + you can add the extension `.awk' to the file name.  This doesn't affect
  2537. + the execution of the `awk' program, but it does make "housekeeping"
  2538. + easier.
  2539. + 
  2540. + File: gawk.info,  Node: Executable Scripts,  Prev: Long,  Up: Running gawk
  2541. + Executable `awk' Programs
  2542. + -------------------------
  2543. +    Once you have learned `awk', you may want to write self-contained
  2544. + `awk' scripts, using the `#!' script mechanism.  You can do this on
  2545. + many Unix systems (1) (and someday on GNU).
  2546. +    For example, you could create a text file named `hello', containing
  2547. + the following (where `BEGIN' is a feature we have not yet discussed):
  2548. +      #! /bin/awk -f
  2549. +      
  2550. +      # a sample awk program
  2551. +      BEGIN    { print "hello, world" }
  2552. + After making this file executable (with the `chmod' command), you can
  2553. + simply type:
  2554. +      hello
  2555. + at the shell, and the system will arrange to run `awk' (2) as if you
  2556. + had typed:
  2557. +      awk -f hello
  2558. + Self-contained `awk' scripts are useful when you want to write a
  2559. + program which users can invoke without knowing that the program is
  2560. + written in `awk'.
  2561. +    If your system does not support the `#!' mechanism, you can get a
  2562. + similar effect using a regular shell script.  It would look something
  2563. + like this:
  2564. +      : The colon makes sure this script is executed by the Bourne shell.
  2565. +      awk 'PROGRAM' "$@"
  2566. +    Using this technique, it is *vital* to enclose the PROGRAM in single
  2567. + quotes to protect it from interpretation by the shell.  If you omit the
  2568. + quotes, only a shell wizard can predict the results.
  2569. +    The `"$@"' causes the shell to forward all the command line
  2570. + arguments to the `awk' program, without interpretation.  The first
  2571. + line, which starts with a colon, is used so that this shell script will
  2572. + work even if invoked by a user who uses the C shell.
  2573. +    ---------- Footnotes ----------
  2574. +    (1)  The `#!' mechanism works on Unix systems derived from Berkeley
  2575. + Unix, System V Release 4, and some System V Release 3 systems.
  2576. +    (2)  The line beginning with `#!' lists the full pathname of an
  2577. + interpreter to be run, and an optional initial command line argument to
  2578. + pass to that interpreter.  The operating system then runs the
  2579. + interpreter with the given argument and the full argument list of the
  2580. + executed program.  The first argument in the list is the full pathname
  2581. + of the `awk' program.  The rest of the argument list will either be
  2582. + options to `awk', or data files, or both.
  2583. + 
  2584. + File: gawk.info,  Node: Comments,  Next: Statements/Lines,  Prev: Running gawk,  Up: Getting Started
  2585. + Comments in `awk' Programs
  2586. + ==========================
  2587. +    A "comment" is some text that is included in a program for the sake
  2588. + of human readers, and that is not really part of the program.  Comments
  2589. + can explain what the program does, and how it works.  Nearly all
  2590. + programming languages have provisions for comments, because programs are
  2591. + typically hard to understand without their extra help.
  2592. +    In the `awk' language, a comment starts with the sharp sign
  2593. + character, `#', and continues to the end of the line.  The `awk'
  2594. + language ignores the rest of a line following a sharp sign.  For
  2595. + example, we could have put the following into `th-prog':
  2596. +      # This program finds records containing the pattern `th'.  This is how
  2597. +      # you continue comments on additional lines.
  2598. +      /th/
  2599. +    You can put comment lines into keyboard-composed throw-away `awk'
  2600. + programs also, but this usually isn't very useful; the purpose of a
  2601. + comment is to help you or another person understand the program at a
  2602. + later time.
  2603. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-2 gawk-2.15.5/gawk.info-2
  2604. *** /src/baseline/gawk-2.15.5/gawk.info-2    Thu Jan  1 00:00:00 1970
  2605. --- gawk-2.15.5/gawk.info-2    Sun Jun 12 22:28:49 1994
  2606. ***************
  2607. *** 0 ****
  2608. --- 1,1236 ----
  2609. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  2610. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  2611. +    This file documents `awk', a program that you can use to select
  2612. + particular records in a file and perform operations upon them.
  2613. +    This is Edition 0.15 of `The GAWK Manual',
  2614. + for the 2.15 version of the GNU implementation
  2615. + of AWK.
  2616. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  2617. +    Permission is granted to make and distribute verbatim copies of this
  2618. + manual provided the copyright notice and this permission notice are
  2619. + preserved on all copies.
  2620. +    Permission is granted to copy and distribute modified versions of
  2621. + this manual under the conditions for verbatim copying, provided that
  2622. + the entire resulting derived work is distributed under the terms of a
  2623. + permission notice identical to this one.
  2624. +    Permission is granted to copy and distribute translations of this
  2625. + manual into another language, under the above conditions for modified
  2626. + versions, except that this permission notice may be stated in a
  2627. + translation approved by the Foundation.
  2628. + 
  2629. + File: gawk.info,  Node: Statements/Lines,  Next: When,  Prev: Comments,  Up: Getting Started
  2630. + `awk' Statements versus Lines
  2631. + =============================
  2632. +    Most often, each line in an `awk' program is a separate statement or
  2633. + separate rule, like this:
  2634. +      awk '/12/  { print $0 }
  2635. +           /21/  { print $0 }' BBS-list inventory-shipped
  2636. +    But sometimes statements can be more than one line, and lines can
  2637. + contain several statements.  You can split a statement into multiple
  2638. + lines by inserting a newline after any of the following:
  2639. +      ,    {    ?    :    ||    &&    do    else
  2640. + A newline at any other point is considered the end of the statement.
  2641. + (Splitting lines after `?' and `:' is a minor `gawk' extension.  The
  2642. + `?' and `:' referred to here is the three operand conditional
  2643. + expression described in *Note Conditional Expressions: Conditional Exp.)
  2644. +    If you would like to split a single statement into two lines at a
  2645. + point where a newline would terminate it, you can "continue" it by
  2646. + ending the first line with a backslash character, `\'.  This is allowed
  2647. + absolutely anywhere in the statement, even in the middle of a string or
  2648. + regular expression.  For example:
  2649. +      awk '/This program is too long, so continue it\
  2650. +       on the next line/ { print $1 }'
  2651. + We have generally not used backslash continuation in the sample
  2652. + programs in this manual.  Since in `gawk' there is no limit on the
  2653. + length of a line, it is never strictly necessary; it just makes
  2654. + programs prettier.  We have preferred to make them even more pretty by
  2655. + keeping the statements short.  Backslash continuation is most useful
  2656. + when your `awk' program is in a separate source file, instead of typed
  2657. + in on the command line.  You should also note that many `awk'
  2658. + implementations are more picky about where you may use backslash
  2659. + continuation.  For maximal portability of your `awk' programs, it is
  2660. + best not to split your lines in the middle of a regular expression or a
  2661. + string.
  2662. +    *Warning: backslash continuation does not work as described above
  2663. + with the C shell.*  Continuation with backslash works for `awk'
  2664. + programs in files, and also for one-shot programs *provided* you are
  2665. + using a POSIX-compliant shell, such as the Bourne shell or the
  2666. + Bourne-again shell.  But the C shell used on Berkeley Unix behaves
  2667. + differently!  There, you must use two backslashes in a row, followed by
  2668. + a newline.
  2669. +    When `awk' statements within one rule are short, you might want to
  2670. + put more than one of them on a line.  You do this by separating the
  2671. + statements with a semicolon, `;'.  This also applies to the rules
  2672. + themselves.  Thus, the previous program could have been written:
  2673. +      /12/ { print $0 } ; /21/ { print $0 }
  2674. + *Note:* the requirement that rules on the same line must be separated
  2675. + with a semicolon is a recent change in the `awk' language; it was done
  2676. + for consistency with the treatment of statements within an action.
  2677. + 
  2678. + File: gawk.info,  Node: When,  Prev: Statements/Lines,  Up: Getting Started
  2679. + When to Use `awk'
  2680. + =================
  2681. +    You might wonder how `awk' might be useful for you.  Using additional
  2682. + utility programs, more advanced patterns, field separators, arithmetic
  2683. + statements, and other selection criteria, you can produce much more
  2684. + complex output.  The `awk' language is very useful for producing
  2685. + reports from large amounts of raw data, such as summarizing information
  2686. + from the output of other utility programs like `ls'.  (*Note A More
  2687. + Complex Example: More Complex.)
  2688. +    Programs written with `awk' are usually much smaller than they would
  2689. + be in other languages.  This makes `awk' programs easy to compose and
  2690. + use.  Often `awk' programs can be quickly composed at your terminal,
  2691. + used once, and thrown away.  Since `awk' programs are interpreted, you
  2692. + can avoid the usually lengthy edit-compile-test-debug cycle of software
  2693. + development.
  2694. +    Complex programs have been written in `awk', including a complete
  2695. + retargetable assembler for 8-bit microprocessors (*note Glossary::., for
  2696. + more information) and a microcode assembler for a special purpose Prolog
  2697. + computer.  However, `awk''s capabilities are strained by tasks of such
  2698. + complexity.
  2699. +    If you find yourself writing `awk' scripts of more than, say, a few
  2700. + hundred lines, you might consider using a different programming
  2701. + language.  Emacs Lisp is a good choice if you need sophisticated string
  2702. + or pattern matching capabilities.  The shell is also good at string and
  2703. + pattern matching; in addition, it allows powerful use of the system
  2704. + utilities.  More conventional languages, such as C, C++, and Lisp, offer
  2705. + better facilities for system programming and for managing the complexity
  2706. + of large programs.  Programs in these languages may require more lines
  2707. + of source code than the equivalent `awk' programs, but they are easier
  2708. + to maintain and usually run more efficiently.
  2709. + 
  2710. + File: gawk.info,  Node: Reading Files,  Next: Printing,  Prev: Getting Started,  Up: Top
  2711. + Reading Input Files
  2712. + *******************
  2713. +    In the typical `awk' program, all input is read either from the
  2714. + standard input (by default the keyboard, but often a pipe from another
  2715. + command) or from files whose names you specify on the `awk' command
  2716. + line.  If you specify input files, `awk' reads them in order, reading
  2717. + all the data from one before going on to the next.  The name of the
  2718. + current input file can be found in the built-in variable `FILENAME'
  2719. + (*note Built-in Variables::.).
  2720. +    The input is read in units called records, and processed by the
  2721. + rules one record at a time.  By default, each record is one line.  Each
  2722. + record is split automatically into fields, to make it more convenient
  2723. + for a rule to work on its parts.
  2724. +    On rare occasions you will need to use the `getline' command, which
  2725. + can do explicit input from any number of files (*note Explicit Input
  2726. + with `getline': Getline.).
  2727. + * Menu:
  2728. + * Records::                     Controlling how data is split into records.
  2729. + * Fields::                      An introduction to fields.
  2730. + * Non-Constant Fields::         Non-constant Field Numbers.
  2731. + * Changing Fields::             Changing the Contents of a Field.
  2732. + * Field Separators::            The field separator and how to change it.
  2733. + * Constant Size::               Reading constant width data.
  2734. + * Multiple Line::               Reading multi-line records.
  2735. + * Getline::                     Reading files under explicit program control
  2736. +                                 using the `getline' function.
  2737. + * Close Input::                 Closing an input file (so you can read from
  2738. +                                 the beginning once more).
  2739. + 
  2740. + File: gawk.info,  Node: Records,  Next: Fields,  Prev: Reading Files,  Up: Reading Files
  2741. + How Input is Split into Records
  2742. + ===============================
  2743. +    The `awk' language divides its input into records and fields.
  2744. + Records are separated by a character called the "record separator".  By
  2745. + default, the record separator is the newline character, defining a
  2746. + record to be a single line of text.
  2747. +    Sometimes you may want to use a different character to separate your
  2748. + records.  You can use a different character by changing the built-in
  2749. + variable `RS'.  The value of `RS' is a string that says how to separate
  2750. + records; the default value is `"\n"', the string containing just a
  2751. + newline character.  This is why records are, by default, single lines.
  2752. +    `RS' can have any string as its value, but only the first character
  2753. + of the string is used as the record separator.  The other characters are
  2754. + ignored.  `RS' is exceptional in this regard; `awk' uses the full value
  2755. + of all its other built-in variables.
  2756. +    You can change the value of `RS' in the `awk' program with the
  2757. + assignment operator, `=' (*note Assignment Expressions: Assignment
  2758. + Ops.).  The new record-separator character should be enclosed in
  2759. + quotation marks to make a string constant.  Often the right time to do
  2760. + this is at the beginning of execution, before any input has been
  2761. + processed, so that the very first record will be read with the proper
  2762. + separator.  To do this, use the special `BEGIN' pattern (*note `BEGIN'
  2763. + and `END' Special Patterns: BEGIN/END.).  For example:
  2764. +      awk 'BEGIN { RS = "/" } ; { print $0 }' BBS-list
  2765. + changes the value of `RS' to `"/"', before reading any input.  This is
  2766. + a string whose first character is a slash; as a result, records are
  2767. + separated by slashes.  Then the input file is read, and the second rule
  2768. + in the `awk' program (the action with no pattern) prints each record.
  2769. + Since each `print' statement adds a newline at the end of its output,
  2770. + the effect of this `awk' program is to copy the input with each slash
  2771. + changed to a newline.
  2772. +    Another way to change the record separator is on the command line,
  2773. + using the variable-assignment feature (*note Invoking `awk': Command
  2774. + Line.).
  2775. +      awk '{ print $0 }' RS="/" BBS-list
  2776. + This sets `RS' to `/' before processing `BBS-list'.
  2777. +    Reaching the end of an input file terminates the current input
  2778. + record, even if the last character in the file is not the character in
  2779. + `RS'.
  2780. +    The empty string, `""' (a string of no characters), has a special
  2781. + meaning as the value of `RS': it means that records are separated only
  2782. + by blank lines.  *Note Multiple-Line Records: Multiple Line, for more
  2783. + details.
  2784. +    The `awk' utility keeps track of the number of records that have
  2785. + been read so far from the current input file.  This value is stored in a
  2786. + built-in variable called `FNR'.  It is reset to zero when a new file is
  2787. + started.  Another built-in variable, `NR', is the total number of input
  2788. + records read so far from all files.  It starts at zero but is never
  2789. + automatically reset to zero.
  2790. +    If you change the value of `RS' in the middle of an `awk' run, the
  2791. + new value is used to delimit subsequent records, but the record
  2792. + currently being processed (and records already processed) are not
  2793. + affected.
  2794. + 
  2795. + File: gawk.info,  Node: Fields,  Next: Non-Constant Fields,  Prev: Records,  Up: Reading Files
  2796. + Examining Fields
  2797. + ================
  2798. +    When `awk' reads an input record, the record is automatically
  2799. + separated or "parsed" by the interpreter into chunks called "fields".
  2800. + By default, fields are separated by whitespace, like words in a line.
  2801. + Whitespace in `awk' means any string of one or more spaces and/or tabs;
  2802. + other characters such as newline, formfeed, and so on, that are
  2803. + considered whitespace by other languages are *not* considered
  2804. + whitespace by `awk'.
  2805. +    The purpose of fields is to make it more convenient for you to refer
  2806. + to these pieces of the record.  You don't have to use them--you can
  2807. + operate on the whole record if you wish--but fields are what make
  2808. + simple `awk' programs so powerful.
  2809. +    To refer to a field in an `awk' program, you use a dollar-sign, `$',
  2810. + followed by the number of the field you want.  Thus, `$1' refers to the
  2811. + first field, `$2' to the second, and so on.  For example, suppose the
  2812. + following is a line of input:
  2813. +      This seems like a pretty nice example.
  2814. + Here the first field, or `$1', is `This'; the second field, or `$2', is
  2815. + `seems'; and so on.  Note that the last field, `$7', is `example.'.
  2816. + Because there is no space between the `e' and the `.', the period is
  2817. + considered part of the seventh field.
  2818. +    No matter how many fields there are, the last field in a record can
  2819. + be represented by `$NF'.  So, in the example above, `$NF' would be the
  2820. + same as `$7', which is `example.'.  Why this works is explained below
  2821. + (*note Non-constant Field Numbers: Non-Constant Fields.).  If you try
  2822. + to refer to a field beyond the last one, such as `$8' when the record
  2823. + has only 7 fields, you get the empty string.
  2824. +    Plain `NF', with no `$', is a built-in variable whose value is the
  2825. + number of fields in the current record.
  2826. +    `$0', which looks like an attempt to refer to the zeroth field, is a
  2827. + special case: it represents the whole input record.  This is what you
  2828. + would use if you weren't interested in fields.
  2829. +    Here are some more examples:
  2830. +      awk '$1 ~ /foo/ { print $0 }' BBS-list
  2831. + This example prints each record in the file `BBS-list' whose first
  2832. + field contains the string `foo'.  The operator `~' is called a
  2833. + "matching operator" (*note Comparison Expressions: Comparison Ops.); it
  2834. + tests whether a string (here, the field `$1') matches a given regular
  2835. + expression.
  2836. +    By contrast, the following example:
  2837. +      awk '/foo/ { print $1, $NF }' BBS-list
  2838. + looks for `foo' in *the entire record* and prints the first field and
  2839. + the last field for each input record containing a match.
  2840. + 
  2841. + File: gawk.info,  Node: Non-Constant Fields,  Next: Changing Fields,  Prev: Fields,  Up: Reading Files
  2842. + Non-constant Field Numbers
  2843. + ==========================
  2844. +    The number of a field does not need to be a constant.  Any
  2845. + expression in the `awk' language can be used after a `$' to refer to a
  2846. + field.  The value of the expression specifies the field number.  If the
  2847. + value is a string, rather than a number, it is converted to a number.
  2848. + Consider this example:
  2849. +      awk '{ print $NR }'
  2850. + Recall that `NR' is the number of records read so far: 1 in the first
  2851. + record, 2 in the second, etc.  So this example prints the first field
  2852. + of the first record, the second field of the second record, and so on.
  2853. + For the twentieth record, field number 20 is printed; most likely, the
  2854. + record has fewer than 20 fields, so this prints a blank line.
  2855. +    Here is another example of using expressions as field numbers:
  2856. +      awk '{ print $(2*2) }' BBS-list
  2857. +    The `awk' language must evaluate the expression `(2*2)' and use its
  2858. + value as the number of the field to print.  The `*' sign represents
  2859. + multiplication, so the expression `2*2' evaluates to 4.  The
  2860. + parentheses are used so that the multiplication is done before the `$'
  2861. + operation; they are necessary whenever there is a binary operator in
  2862. + the field-number expression.  This example, then, prints the hours of
  2863. + operation (the fourth field) for every line of the file `BBS-list'.
  2864. +    If the field number you compute is zero, you get the entire record.
  2865. + Thus, `$(2-2)' has the same value as `$0'.  Negative field numbers are
  2866. + not allowed.
  2867. +    The number of fields in the current record is stored in the built-in
  2868. + variable `NF' (*note Built-in Variables::.).  The expression `$NF' is
  2869. + not a special feature: it is the direct consequence of evaluating `NF'
  2870. + and using its value as a field number.
  2871. + 
  2872. + File: gawk.info,  Node: Changing Fields,  Next: Field Separators,  Prev: Non-Constant Fields,  Up: Reading Files
  2873. + Changing the Contents of a Field
  2874. + ================================
  2875. +    You can change the contents of a field as seen by `awk' within an
  2876. + `awk' program; this changes what `awk' perceives as the current input
  2877. + record.  (The actual input is untouched: `awk' never modifies the input
  2878. + file.)
  2879. +    Consider this example:
  2880. +      awk '{ $3 = $2 - 10; print $2, $3 }' inventory-shipped
  2881. + The `-' sign represents subtraction, so this program reassigns field
  2882. + three, `$3', to be the value of field two minus ten, `$2 - 10'.  (*Note
  2883. + Arithmetic Operators: Arithmetic Ops.) Then field two, and the new
  2884. + value for field three, are printed.
  2885. +    In order for this to work, the text in field `$2' must make sense as
  2886. + a number; the string of characters must be converted to a number in
  2887. + order for the computer to do arithmetic on it.  The number resulting
  2888. + from the subtraction is converted back to a string of characters which
  2889. + then becomes field three.  *Note Conversion of Strings and Numbers:
  2890. + Conversion.
  2891. +    When you change the value of a field (as perceived by `awk'), the
  2892. + text of the input record is recalculated to contain the new field where
  2893. + the old one was.  Therefore, `$0' changes to reflect the altered field.
  2894. + Thus,
  2895. +      awk '{ $2 = $2 - 10; print $0 }' inventory-shipped
  2896. + prints a copy of the input file, with 10 subtracted from the second
  2897. + field of each line.
  2898. +    You can also assign contents to fields that are out of range.  For
  2899. + example:
  2900. +      awk '{ $6 = ($5 + $4 + $3 + $2) ; print $6 }' inventory-shipped
  2901. + We've just created `$6', whose value is the sum of fields `$2', `$3',
  2902. + `$4', and `$5'.  The `+' sign represents addition.  For the file
  2903. + `inventory-shipped', `$6' represents the total number of parcels
  2904. + shipped for a particular month.
  2905. +    Creating a new field changes the internal `awk' copy of the current
  2906. + input record--the value of `$0'.  Thus, if you do `print $0' after
  2907. + adding a field, the record printed includes the new field, with the
  2908. + appropriate number of field separators between it and the previously
  2909. + existing fields.
  2910. +    This recomputation affects and is affected by several features not
  2911. + yet discussed, in particular, the "output field separator", `OFS',
  2912. + which is used to separate the fields (*note Output Separators::.), and
  2913. + `NF' (the number of fields; *note Examining Fields: Fields.).  For
  2914. + example, the value of `NF' is set to the number of the highest field
  2915. + you create.
  2916. +    Note, however, that merely *referencing* an out-of-range field does
  2917. + *not* change the value of either `$0' or `NF'.  Referencing an
  2918. + out-of-range field merely produces a null string.  For example:
  2919. +      if ($(NF+1) != "")
  2920. +          print "can't happen"
  2921. +      else
  2922. +          print "everything is normal"
  2923. + should print `everything is normal', because `NF+1' is certain to be
  2924. + out of range.  (*Note The `if' Statement: If Statement, for more
  2925. + information about `awk''s `if-else' statements.)
  2926. +    It is important to note that assigning to a field will change the
  2927. + value of `$0', but will not change the value of `NF', even when you
  2928. + assign the null string to a field.  For example:
  2929. +      echo a b c d | awk '{ OFS = ":"; $2 = "" ; print ; print NF }'
  2930. + prints
  2931. +      a::c:d
  2932. +      4
  2933. + The field is still there, it just has an empty value.  You can tell
  2934. + because there are two colons in a row.
  2935. + 
  2936. + File: gawk.info,  Node: Field Separators,  Next: Constant Size,  Prev: Changing Fields,  Up: Reading Files
  2937. + Specifying how Fields are Separated
  2938. + ===================================
  2939. +    (This section is rather long; it describes one of the most
  2940. + fundamental operations in `awk'.  If you are a novice with `awk', we
  2941. + recommend that you re-read this section after you have studied the
  2942. + section on regular expressions, *Note Regular Expressions as Patterns:
  2943. + Regexp.)
  2944. +    The way `awk' splits an input record into fields is controlled by
  2945. + the "field separator", which is a single character or a regular
  2946. + expression.  `awk' scans the input record for matches for the
  2947. + separator; the fields themselves are the text between the matches.  For
  2948. + example, if the field separator is `oo', then the following line:
  2949. +      moo goo gai pan
  2950. + would be split into three fields: `m', ` g' and ` gai  pan'.
  2951. +    The field separator is represented by the built-in variable `FS'.
  2952. + Shell programmers take note!  `awk' does not use the name `IFS' which
  2953. + is used by the shell.
  2954. +    You can change the value of `FS' in the `awk' program with the
  2955. + assignment operator, `=' (*note Assignment Expressions: Assignment
  2956. + Ops.).  Often the right time to do this is at the beginning of
  2957. + execution, before any input has been processed, so that the very first
  2958. + record will be read with the proper separator.  To do this, use the
  2959. + special `BEGIN' pattern (*note `BEGIN' and `END' Special Patterns:
  2960. + BEGIN/END.).  For example, here we set the value of `FS' to the string
  2961. + `","':
  2962. +      awk 'BEGIN { FS = "," } ; { print $2 }'
  2963. + Given the input line,
  2964. +      John Q. Smith, 29 Oak St., Walamazoo, MI 42139
  2965. + this `awk' program extracts the string ` 29 Oak St.'.
  2966. +    Sometimes your input data will contain separator characters that
  2967. + don't separate fields the way you thought they would.  For instance, the
  2968. + person's name in the example we've been using might have a title or
  2969. + suffix attached, such as `John Q. Smith, LXIX'.  From input containing
  2970. + such a name:
  2971. +      John Q. Smith, LXIX, 29 Oak St., Walamazoo, MI 42139
  2972. + the previous sample program would extract ` LXIX', instead of ` 29 Oak
  2973. + St.'.  If you were expecting the program to print the address, you
  2974. + would be surprised.  So choose your data layout and separator
  2975. + characters carefully to prevent such problems.
  2976. +    As you know, by default, fields are separated by whitespace sequences
  2977. + (spaces and tabs), not by single spaces: two spaces in a row do not
  2978. + delimit an empty field.  The default value of the field separator is a
  2979. + string `" "' containing a single space.  If this value were interpreted
  2980. + in the usual way, each space character would separate fields, so two
  2981. + spaces in a row would make an empty field between them.  The reason
  2982. + this does not happen is that a single space as the value of `FS' is a
  2983. + special case: it is taken to specify the default manner of delimiting
  2984. + fields.
  2985. +    If `FS' is any other single character, such as `","', then each
  2986. + occurrence of that character separates two fields.  Two consecutive
  2987. + occurrences delimit an empty field.  If the character occurs at the
  2988. + beginning or the end of the line, that too delimits an empty field.  The
  2989. + space character is the only single character which does not follow these
  2990. + rules.
  2991. +    More generally, the value of `FS' may be a string containing any
  2992. + regular expression.  Then each match in the record for the regular
  2993. + expression separates fields.  For example, the assignment:
  2994. +      FS = ", \t"
  2995. + makes every area of an input line that consists of a comma followed by a
  2996. + space and a tab, into a field separator.  (`\t' stands for a tab.)
  2997. +    For a less trivial example of a regular expression, suppose you want
  2998. + single spaces to separate fields the way single commas were used above.
  2999. + You can set `FS' to `"[ ]"'.  This regular expression matches a single
  3000. + space and nothing else.
  3001. +    `FS' can be set on the command line.  You use the `-F' argument to
  3002. + do so.  For example:
  3003. +      awk -F, 'PROGRAM' INPUT-FILES
  3004. + sets `FS' to be the `,' character.  Notice that the argument uses a
  3005. + capital `F'.  Contrast this with `-f', which specifies a file
  3006. + containing an `awk' program.  Case is significant in command options:
  3007. + the `-F' and `-f' options have nothing to do with each other.  You can
  3008. + use both options at the same time to set the `FS' argument *and* get an
  3009. + `awk' program from a file.
  3010. +    The value used for the argument to `-F' is processed in exactly the
  3011. + same way as assignments to the built-in variable `FS'.  This means that
  3012. + if the field separator contains special characters, they must be escaped
  3013. + appropriately.  For example, to use a `\' as the field separator, you
  3014. + would have to type:
  3015. +      # same as FS = "\\"
  3016. +      awk -F\\\\ '...' files ...
  3017. + Since `\' is used for quoting in the shell, `awk' will see `-F\\'.
  3018. + Then `awk' processes the `\\' for escape characters (*note Constant
  3019. + Expressions: Constants.), finally yielding a single `\' to be used for
  3020. + the field separator.
  3021. +    As a special case, in compatibility mode (*note Invoking `awk':
  3022. + Command Line.), if the argument to `-F' is `t', then `FS' is set to the
  3023. + tab character.  (This is because if you type `-F\t', without the quotes,
  3024. + at the shell, the `\' gets deleted, so `awk' figures that you really
  3025. + want your fields to be separated with tabs, and not `t's.  Use `-v
  3026. + FS="t"' on the command line if you really do want to separate your
  3027. + fields with `t's.)
  3028. +    For example, let's use an `awk' program file called `baud.awk' that
  3029. + contains the pattern `/300/', and the action `print $1'.  Here is the
  3030. + program:
  3031. +      /300/   { print $1 }
  3032. +    Let's also set `FS' to be the `-' character, and run the program on
  3033. + the file `BBS-list'.  The following command prints a list of the names
  3034. + of the bulletin boards that operate at 300 baud and the first three
  3035. + digits of their phone numbers:
  3036. +      awk -F- -f baud.awk BBS-list
  3037. + It produces this output:
  3038. +      aardvark     555
  3039. +      alpo
  3040. +      barfly       555
  3041. +      bites        555
  3042. +      camelot      555
  3043. +      core         555
  3044. +      fooey        555
  3045. +      foot         555
  3046. +      macfoo       555
  3047. +      sdace        555
  3048. +      sabafoo      555
  3049. + Note the second line of output.  If you check the original file, you
  3050. + will see that the second line looked like this:
  3051. +      alpo-net     555-3412     2400/1200/300     A
  3052. +    The `-' as part of the system's name was used as the field
  3053. + separator, instead of the `-' in the phone number that was originally
  3054. + intended.  This demonstrates why you have to be careful in choosing
  3055. + your field and record separators.
  3056. +    The following program searches the system password file, and prints
  3057. + the entries for users who have no password:
  3058. +      awk -F: '$2 == ""' /etc/passwd
  3059. + Here we use the `-F' option on the command line to set the field
  3060. + separator.  Note that fields in `/etc/passwd' are separated by colons.
  3061. + The second field represents a user's encrypted password, but if the
  3062. + field is empty, that user has no password.
  3063. +    According to the POSIX standard, `awk' is supposed to behave as if
  3064. + each record is split into fields at the time that it is read.  In
  3065. + particular, this means that you can change the value of `FS' after a
  3066. + record is read, but before any of the fields are referenced.  The value
  3067. + of the fields (i.e. how they were split) should reflect the old value
  3068. + of `FS', not the new one.
  3069. +    However, many implementations of `awk' do not do this.  Instead,
  3070. + they defer splitting the fields until a field reference actually
  3071. + happens, using the *current* value of `FS'!  This behavior can be
  3072. + difficult to diagnose. The following example illustrates the results of
  3073. + the two methods.  (The `sed' command prints just the first line of
  3074. + `/etc/passwd'.)
  3075. +      sed 1q /etc/passwd | awk '{ FS = ":" ; print $1 }'
  3076. + will usually print
  3077. +      root
  3078. + on an incorrect implementation of `awk', while `gawk' will print
  3079. + something like
  3080. +      root:nSijPlPhZZwgE:0:0:Root:/:
  3081. +    There is an important difference between the two cases of `FS = " "'
  3082. + (a single blank) and `FS = "[ \t]+"' (which is a regular expression
  3083. + matching one or more blanks or tabs).  For both values of `FS', fields
  3084. + are separated by runs of blanks and/or tabs.  However, when the value of
  3085. + `FS' is `" "', `awk' will strip leading and trailing whitespace from
  3086. + the record, and then decide where the fields are.
  3087. +    For example, the following expression prints `b':
  3088. +      echo ' a b c d ' | awk '{ print $2 }'
  3089. + However, the following prints `a':
  3090. +      echo ' a b c d ' | awk 'BEGIN { FS = "[ \t]+" } ; { print $2 }'
  3091. + In this case, the first field is null.
  3092. +    The stripping of leading and trailing whitespace also comes into
  3093. + play whenever `$0' is recomputed.  For instance, this pipeline
  3094. +      echo '   a b c d' | awk '{ print; $2 = $2; print }'
  3095. + produces this output:
  3096. +         a b c d
  3097. +      a b c d
  3098. + The first `print' statement prints the record as it was read, with
  3099. + leading whitespace intact.  The assignment to `$2' rebuilds `$0' by
  3100. + concatenating `$1' through `$NF' together, separated by the value of
  3101. + `OFS'.  Since the leading whitespace was ignored when finding `$1', it
  3102. + is not part of the new `$0'.  Finally, the last `print' statement
  3103. + prints the new `$0'.
  3104. +    The following table summarizes how fields are split, based on the
  3105. + value of `FS'.
  3106. + `FS == " "'
  3107. +      Fields are separated by runs of whitespace.  Leading and trailing
  3108. +      whitespace are ignored.  This is the default.
  3109. + `FS == ANY SINGLE CHARACTER'
  3110. +      Fields are separated by each occurrence of the character.  Multiple
  3111. +      successive occurrences delimit empty fields, as do leading and
  3112. +      trailing occurrences.
  3113. + `FS == REGEXP'
  3114. +      Fields are separated by occurrences of characters that match
  3115. +      REGEXP.  Leading and trailing matches of REGEXP delimit empty
  3116. +      fields.
  3117. + 
  3118. + File: gawk.info,  Node: Constant Size,  Next: Multiple Line,  Prev: Field Separators,  Up: Reading Files
  3119. + Reading Fixed-width Data
  3120. + ========================
  3121. +    (This section discusses an advanced, experimental feature.  If you
  3122. + are a novice `awk' user, you may wish to skip it on the first reading.)
  3123. +    `gawk' 2.13 introduced a new facility for dealing with fixed-width
  3124. + fields with no distinctive field separator.  Data of this nature arises
  3125. + typically in one of at least two ways:  the input for old FORTRAN
  3126. + programs where numbers are run together, and the output of programs
  3127. + that did not anticipate the use of their output as input for other
  3128. + programs.
  3129. +    An example of the latter is a table where all the columns are lined
  3130. + up by the use of a variable number of spaces and *empty fields are just
  3131. + spaces*.  Clearly, `awk''s normal field splitting based on `FS' will
  3132. + not work well in this case.  (Although a portable `awk' program can use
  3133. + a series of `substr' calls on `$0', this is awkward and inefficient for
  3134. + a large number of fields.)
  3135. +    The splitting of an input record into fixed-width fields is
  3136. + specified by assigning a string containing space-separated numbers to
  3137. + the built-in variable `FIELDWIDTHS'.  Each number specifies the width
  3138. + of the field *including* columns between fields.  If you want to ignore
  3139. + the columns between fields, you can specify the width as a separate
  3140. + field that is subsequently ignored.
  3141. +    The following data is the output of the `w' utility.  It is useful
  3142. + to illustrate the use of `FIELDWIDTHS'.
  3143. +       10:06pm  up 21 days, 14:04,  23 users
  3144. +      User     tty       login  idle   JCPU   PCPU  what
  3145. +      hzuo     ttyV0     8:58pm            9      5  vi p24.tex
  3146. +      hzang    ttyV3     6:37pm    50                -csh
  3147. +      eklye    ttyV5     9:53pm            7      1  em thes.tex
  3148. +      dportein ttyV6     8:17pm  1:47                -csh
  3149. +      gierd    ttyD3    10:00pm     1                elm
  3150. +      dave     ttyD4     9:47pm            4      4  w
  3151. +      brent    ttyp0    26Jun91  4:46  26:46   4:41  bash
  3152. +      dave     ttyq4    26Jun9115days     46     46  wnewmail
  3153. +    The following program takes the above input, converts the idle time
  3154. + to number of seconds and prints out the first two fields and the
  3155. + calculated idle time.  (This program uses a number of `awk' features
  3156. + that haven't been introduced yet.)
  3157. +      BEGIN  { FIELDWIDTHS = "9 6 10 6 7 7 35" }
  3158. +      NR > 2 {
  3159. +          idle = $4
  3160. +          sub(/^  */, "", idle)   # strip leading spaces
  3161. +          if (idle == "") idle = 0
  3162. +          if (idle ~ /:/) { split(idle, t, ":"); idle = t[1] * 60 + t[2] }
  3163. +          if (idle ~ /days/) { idle *= 24 * 60 * 60 }
  3164. +      
  3165. +          print $1, $2, idle
  3166. +      }
  3167. +    Here is the result of running the program on the data:
  3168. +      hzuo      ttyV0  0
  3169. +      hzang     ttyV3  50
  3170. +      eklye     ttyV5  0
  3171. +      dportein  ttyV6  107
  3172. +      gierd     ttyD3  1
  3173. +      dave      ttyD4  0
  3174. +      brent     ttyp0  286
  3175. +      dave      ttyq4  1296000
  3176. +    Another (possibly more practical) example of fixed-width input data
  3177. + would be the input from a deck of balloting cards.  In some parts of
  3178. + the United States, voters make their choices by punching holes in
  3179. + computer cards.  These cards are then processed to count the votes for
  3180. + any particular candidate or on any particular issue.  Since a voter may
  3181. + choose not to vote on some issue, any column on the card may be empty.
  3182. + An `awk' program for processing such data could use the `FIELDWIDTHS'
  3183. + feature to simplify reading the data.
  3184. +    This feature is still experimental, and will likely evolve over time.
  3185. + 
  3186. + File: gawk.info,  Node: Multiple Line,  Next: Getline,  Prev: Constant Size,  Up: Reading Files
  3187. + Multiple-Line Records
  3188. + =====================
  3189. +    In some data bases, a single line cannot conveniently hold all the
  3190. + information in one entry.  In such cases, you can use multi-line
  3191. + records.
  3192. +    The first step in doing this is to choose your data format: when
  3193. + records are not defined as single lines, how do you want to define them?
  3194. + What should separate records?
  3195. +    One technique is to use an unusual character or string to separate
  3196. + records.  For example, you could use the formfeed character (written
  3197. + `\f' in `awk', as in C) to separate them, making each record a page of
  3198. + the file.  To do this, just set the variable `RS' to `"\f"' (a string
  3199. + containing the formfeed character).  Any other character could equally
  3200. + well be used, as long as it won't be part of the data in a record.
  3201. +    Another technique is to have blank lines separate records.  By a
  3202. + special dispensation, a null string as the value of `RS' indicates that
  3203. + records are separated by one or more blank lines.  If you set `RS' to
  3204. + the null string, a record always ends at the first blank line
  3205. + encountered.  And the next record doesn't start until the first nonblank
  3206. + line that follows--no matter how many blank lines appear in a row, they
  3207. + are considered one record-separator. (End of file is also considered a
  3208. + record separator.)
  3209. +    The second step is to separate the fields in the record.  One way to
  3210. + do this is to put each field on a separate line: to do this, just set
  3211. + the variable `FS' to the string `"\n"'.  (This simple regular
  3212. + expression matches a single newline.)
  3213. +    Another way to separate fields is to divide each of the lines into
  3214. + fields in the normal manner.  This happens by default as a result of a
  3215. + special feature: when `RS' is set to the null string, the newline
  3216. + character *always* acts as a field separator.  This is in addition to
  3217. + whatever field separations result from `FS'.
  3218. +    The original motivation for this special exception was probably so
  3219. + that you get useful behavior in the default case (i.e., `FS == " "').
  3220. + This feature can be a problem if you really don't want the newline
  3221. + character to separate fields, since there is no way to prevent it.
  3222. + However, you can work around this by using the `split' function to
  3223. + break up the record manually (*note Built-in Functions for String
  3224. + Manipulation: String Functions.).
  3225. + 
  3226. + File: gawk.info,  Node: Getline,  Next: Close Input,  Prev: Multiple Line,  Up: Reading Files
  3227. + Explicit Input with `getline'
  3228. + =============================
  3229. +    So far we have been getting our input files from `awk''s main input
  3230. + stream--either the standard input (usually your terminal) or the files
  3231. + specified on the command line.  The `awk' language has a special
  3232. + built-in command called `getline' that can be used to read input under
  3233. + your explicit control.
  3234. +    This command is quite complex and should *not* be used by beginners.
  3235. + It is covered here because this is the chapter on input.  The examples
  3236. + that follow the explanation of the `getline' command include material
  3237. + that has not been covered yet.  Therefore, come back and study the
  3238. + `getline' command *after* you have reviewed the rest of this manual and
  3239. + have a good knowledge of how `awk' works.
  3240. +    `getline' returns 1 if it finds a record, and 0 if the end of the
  3241. + file is encountered.  If there is some error in getting a record, such
  3242. + as a file that cannot be opened, then `getline' returns -1.  In this
  3243. + case, `gawk' sets the variable `ERRNO' to a string describing the error
  3244. + that occurred.
  3245. +    In the following examples, COMMAND stands for a string value that
  3246. + represents a shell command.
  3247. + `getline'
  3248. +      The `getline' command can be used without arguments to read input
  3249. +      from the current input file.  All it does in this case is read the
  3250. +      next input record and split it up into fields.  This is useful if
  3251. +      you've finished processing the current record, but you want to do
  3252. +      some special processing *right now* on the next record.  Here's an
  3253. +      example:
  3254. +           awk '{
  3255. +                if (t = index($0, "/*")) {
  3256. +                     if (t > 1)
  3257. +                          tmp = substr($0, 1, t - 1)
  3258. +                     else
  3259. +                          tmp = ""
  3260. +                     u = index(substr($0, t + 2), "*/")
  3261. +                     while (u == 0) {
  3262. +                          getline
  3263. +                          t = -1
  3264. +                          u = index($0, "*/")
  3265. +                     }
  3266. +                     if (u <= length($0) - 2)
  3267. +                          $0 = tmp substr($0, t + u + 3)
  3268. +                     else
  3269. +                          $0 = tmp
  3270. +                }
  3271. +                print $0
  3272. +           }'
  3273. +      This `awk' program deletes all C-style comments, `/* ...  */',
  3274. +      from the input.  By replacing the `print $0' with other
  3275. +      statements, you could perform more complicated processing on the
  3276. +      decommented input, like searching for matches of a regular
  3277. +      expression.  (This program has a subtle problem--can you spot it?)
  3278. +      This form of the `getline' command sets `NF' (the number of
  3279. +      fields; *note Examining Fields: Fields.), `NR' (the number of
  3280. +      records read so far; *note How Input is Split into Records:
  3281. +      Records.), `FNR' (the number of records read from this input
  3282. +      file), and the value of `$0'.
  3283. +      *Note:* the new value of `$0' is used in testing the patterns of
  3284. +      any subsequent rules.  The original value of `$0' that triggered
  3285. +      the rule which executed `getline' is lost.  By contrast, the
  3286. +      `next' statement reads a new record but immediately begins
  3287. +      processing it normally, starting with the first rule in the
  3288. +      program.  *Note The `next' Statement: Next Statement.
  3289. + `getline VAR'
  3290. +      This form of `getline' reads a record into the variable VAR.  This
  3291. +      is useful when you want your program to read the next record from
  3292. +      the current input file, but you don't want to subject the record
  3293. +      to the normal input processing.
  3294. +      For example, suppose the next line is a comment, or a special
  3295. +      string, and you want to read it, but you must make certain that it
  3296. +      won't trigger any rules.  This version of `getline' allows you to
  3297. +      read that line and store it in a variable so that the main
  3298. +      read-a-line-and-check-each-rule loop of `awk' never sees it.
  3299. +      The following example swaps every two lines of input.  For
  3300. +      example, given:
  3301. +           wan
  3302. +           tew
  3303. +           free
  3304. +           phore
  3305. +      it outputs:
  3306. +           tew
  3307. +           wan
  3308. +           phore
  3309. +           free
  3310. +      Here's the program:
  3311. +           awk '{
  3312. +                if ((getline tmp) > 0) {
  3313. +                     print tmp
  3314. +                     print $0
  3315. +                } else
  3316. +                     print $0
  3317. +           }'
  3318. +      The `getline' function used in this way sets only the variables
  3319. +      `NR' and `FNR' (and of course, VAR).  The record is not split into
  3320. +      fields, so the values of the fields (including `$0') and the value
  3321. +      of `NF' do not change.
  3322. + `getline < FILE'
  3323. +      This form of the `getline' function takes its input from the file
  3324. +      FILE.  Here FILE is a string-valued expression that specifies the
  3325. +      file name.  `< FILE' is called a "redirection" since it directs
  3326. +      input to come from a different place.
  3327. +      This form is useful if you want to read your input from a
  3328. +      particular file, instead of from the main input stream.  For
  3329. +      example, the following program reads its input record from the
  3330. +      file `foo.input' when it encounters a first field with a value
  3331. +      equal to 10 in the current input file.
  3332. +           awk '{
  3333. +               if ($1 == 10) {
  3334. +                    getline < "foo.input"
  3335. +                    print
  3336. +               } else
  3337. +                    print
  3338. +           }'
  3339. +      Since the main input stream is not used, the values of `NR' and
  3340. +      `FNR' are not changed.  But the record read is split into fields in
  3341. +      the normal manner, so the values of `$0' and other fields are
  3342. +      changed.  So is the value of `NF'.
  3343. +      This does not cause the record to be tested against all the
  3344. +      patterns in the `awk' program, in the way that would happen if the
  3345. +      record were read normally by the main processing loop of `awk'.
  3346. +      However the new record is tested against any subsequent rules,
  3347. +      just as when `getline' is used without a redirection.
  3348. + `getline VAR < FILE'
  3349. +      This form of the `getline' function takes its input from the file
  3350. +      FILE and puts it in the variable VAR.  As above, FILE is a
  3351. +      string-valued expression that specifies the file from which to
  3352. +      read.
  3353. +      In this version of `getline', none of the built-in variables are
  3354. +      changed, and the record is not split into fields.  The only
  3355. +      variable changed is VAR.
  3356. +      For example, the following program copies all the input files to
  3357. +      the output, except for records that say `@include FILENAME'.  Such
  3358. +      a record is replaced by the contents of the file FILENAME.
  3359. +           awk '{
  3360. +                if (NF == 2 && $1 == "@include") {
  3361. +                     while ((getline line < $2) > 0)
  3362. +                          print line
  3363. +                     close($2)
  3364. +                } else
  3365. +                     print
  3366. +           }'
  3367. +      Note here how the name of the extra input file is not built into
  3368. +      the program; it is taken from the data, from the second field on
  3369. +      the `@include' line.
  3370. +      The `close' function is called to ensure that if two identical
  3371. +      `@include' lines appear in the input, the entire specified file is
  3372. +      included twice.  *Note Closing Input Files and Pipes: Close Input.
  3373. +      One deficiency of this program is that it does not process nested
  3374. +      `@include' statements the way a true macro preprocessor would.
  3375. + `COMMAND | getline'
  3376. +      You can "pipe" the output of a command into `getline'.  A pipe is
  3377. +      simply a way to link the output of one program to the input of
  3378. +      another.  In this case, the string COMMAND is run as a shell
  3379. +      command and its output is piped into `awk' to be used as input.
  3380. +      This form of `getline' reads one record from the pipe.
  3381. +      For example, the following program copies input to output, except
  3382. +      for lines that begin with `@execute', which are replaced by the
  3383. +      output produced by running the rest of the line as a shell command:
  3384. +           awk '{
  3385. +                if ($1 == "@execute") {
  3386. +                     tmp = substr($0, 10)
  3387. +                     while ((tmp | getline) > 0)
  3388. +                          print
  3389. +                     close(tmp)
  3390. +                } else
  3391. +                     print
  3392. +           }'
  3393. +      The `close' function is called to ensure that if two identical
  3394. +      `@execute' lines appear in the input, the command is run for each
  3395. +      one.  *Note Closing Input Files and Pipes: Close Input.
  3396. +      Given the input:
  3397. +           foo
  3398. +           bar
  3399. +           baz
  3400. +           @execute who
  3401. +           bletch
  3402. +      the program might produce:
  3403. +           foo
  3404. +           bar
  3405. +           baz
  3406. +           hack     ttyv0   Jul 13 14:22
  3407. +           hack     ttyp0   Jul 13 14:23     (gnu:0)
  3408. +           hack     ttyp1   Jul 13 14:23     (gnu:0)
  3409. +           hack     ttyp2   Jul 13 14:23     (gnu:0)
  3410. +           hack     ttyp3   Jul 13 14:23     (gnu:0)
  3411. +           bletch
  3412. +      Notice that this program ran the command `who' and printed the
  3413. +      result.  (If you try this program yourself, you will get different
  3414. +      results, showing you who is logged in on your system.)
  3415. +      This variation of `getline' splits the record into fields, sets the
  3416. +      value of `NF' and recomputes the value of `$0'.  The values of
  3417. +      `NR' and `FNR' are not changed.
  3418. + `COMMAND | getline VAR'
  3419. +      The output of the command COMMAND is sent through a pipe to
  3420. +      `getline' and into the variable VAR.  For example, the following
  3421. +      program reads the current date and time into the variable
  3422. +      `current_time', using the `date' utility, and then prints it.
  3423. +           awk 'BEGIN {
  3424. +                "date" | getline current_time
  3425. +                close("date")
  3426. +                print "Report printed on " current_time
  3427. +           }'
  3428. +      In this version of `getline', none of the built-in variables are
  3429. +      changed, and the record is not split into fields.
  3430. + 
  3431. + File: gawk.info,  Node: Close Input,  Prev: Getline,  Up: Reading Files
  3432. + Closing Input Files and Pipes
  3433. + =============================
  3434. +    If the same file name or the same shell command is used with
  3435. + `getline' more than once during the execution of an `awk' program, the
  3436. + file is opened (or the command is executed) only the first time.  At
  3437. + that time, the first record of input is read from that file or command.
  3438. + The next time the same file or command is used in `getline', another
  3439. + record is read from it, and so on.
  3440. +    This implies that if you want to start reading the same file again
  3441. + from the beginning, or if you want to rerun a shell command (rather than
  3442. + reading more output from the command), you must take special steps.
  3443. + What you must do is use the `close' function, as follows:
  3444. +      close(FILENAME)
  3445. + or
  3446. +      close(COMMAND)
  3447. +    The argument FILENAME or COMMAND can be any expression.  Its value
  3448. + must exactly equal the string that was used to open the file or start
  3449. + the command--for example, if you open a pipe with this:
  3450. +      "sort -r names" | getline foo
  3451. + then you must close it with this:
  3452. +      close("sort -r names")
  3453. +    Once this function call is executed, the next `getline' from that
  3454. + file or command will reopen the file or rerun the command.
  3455. +    `close' returns a value of zero if the close succeeded.  Otherwise,
  3456. + the value will be non-zero.  In this case, `gawk' sets the variable
  3457. + `ERRNO' to a string describing the error that occurred.
  3458. + 
  3459. + File: gawk.info,  Node: Printing,  Next: One-liners,  Prev: Reading Files,  Up: Top
  3460. + Printing Output
  3461. + ***************
  3462. +    One of the most common things that actions do is to output or "print"
  3463. + some or all of the input.  For simple output, use the `print'
  3464. + statement.  For fancier formatting use the `printf' statement.  Both
  3465. + are described in this chapter.
  3466. + * Menu:
  3467. + * Print::                       The `print' statement.
  3468. + * Print Examples::              Simple examples of `print' statements.
  3469. + * Output Separators::           The output separators and how to change them.
  3470. + * OFMT::                        Controlling Numeric Output With `print'.
  3471. + * Printf::                      The `printf' statement.
  3472. + * Redirection::                 How to redirect output to multiple
  3473. +                                 files and pipes.
  3474. + * Special Files::               File name interpretation in `gawk'.
  3475. +                                 `gawk' allows access to
  3476. +                                 inherited file descriptors.
  3477. + 
  3478. + File: gawk.info,  Node: Print,  Next: Print Examples,  Prev: Printing,  Up: Printing
  3479. + The `print' Statement
  3480. + =====================
  3481. +    The `print' statement does output with simple, standardized
  3482. + formatting.  You specify only the strings or numbers to be printed, in a
  3483. + list separated by commas.  They are output, separated by single spaces,
  3484. + followed by a newline.  The statement looks like this:
  3485. +      print ITEM1, ITEM2, ...
  3486. + The entire list of items may optionally be enclosed in parentheses.  The
  3487. + parentheses are necessary if any of the item expressions uses a
  3488. + relational operator; otherwise it could be confused with a redirection
  3489. + (*note Redirecting Output of `print' and `printf': Redirection.).  The
  3490. + relational operators are `==', `!=', `<', `>', `>=', `<=', `~' and `!~'
  3491. + (*note Comparison Expressions: Comparison Ops.).
  3492. +    The items printed can be constant strings or numbers, fields of the
  3493. + current record (such as `$1'), variables, or any `awk' expressions.
  3494. + The `print' statement is completely general for computing *what* values
  3495. + to print.  With two exceptions, you cannot specify *how* to print
  3496. + them--how many columns, whether to use exponential notation or not, and
  3497. + so on.  (*Note Output Separators::, and *Note Controlling Numeric
  3498. + Output with `print': OFMT.) For that, you need the `printf' statement
  3499. + (*note Using `printf' Statements for Fancier Printing: Printf.).
  3500. +    The simple statement `print' with no items is equivalent to `print
  3501. + $0': it prints the entire current record.  To print a blank line, use
  3502. + `print ""', where `""' is the null, or empty, string.
  3503. +    To print a fixed piece of text, use a string constant such as
  3504. + `"Hello there"' as one item.  If you forget to use the double-quote
  3505. + characters, your text will be taken as an `awk' expression, and you
  3506. + will probably get an error.  Keep in mind that a space is printed
  3507. + between any two items.
  3508. +    Most often, each `print' statement makes one line of output.  But it
  3509. + isn't limited to one line.  If an item value is a string that contains a
  3510. + newline, the newline is output along with the rest of the string.  A
  3511. + single `print' can make any number of lines this way.
  3512. + 
  3513. + File: gawk.info,  Node: Print Examples,  Next: Output Separators,  Prev: Print,  Up: Printing
  3514. + Examples of `print' Statements
  3515. + ==============================
  3516. +    Here is an example of printing a string that contains embedded
  3517. + newlines:
  3518. +      awk 'BEGIN { print "line one\nline two\nline three" }'
  3519. + produces output like this:
  3520. +      line one
  3521. +      line two
  3522. +      line three
  3523. +    Here is an example that prints the first two fields of each input
  3524. + record, with a space between them:
  3525. +      awk '{ print $1, $2 }' inventory-shipped
  3526. + Its output looks like this:
  3527. +      Jan 13
  3528. +      Feb 15
  3529. +      Mar 15
  3530. +      ...
  3531. +    A common mistake in using the `print' statement is to omit the comma
  3532. + between two items.  This often has the effect of making the items run
  3533. + together in the output, with no space.  The reason for this is that
  3534. + juxtaposing two string expressions in `awk' means to concatenate them.
  3535. + For example, without the comma:
  3536. +      awk '{ print $1 $2 }' inventory-shipped
  3537. + prints:
  3538. +      Jan13
  3539. +      Feb15
  3540. +      Mar15
  3541. +      ...
  3542. +    Neither example's output makes much sense to someone unfamiliar with
  3543. + the file `inventory-shipped'.  A heading line at the beginning would
  3544. + make it clearer.  Let's add some headings to our table of months (`$1')
  3545. + and green crates shipped (`$2').  We do this using the `BEGIN' pattern
  3546. + (*note `BEGIN' and `END' Special Patterns: BEGIN/END.) to force the
  3547. + headings to be printed only once:
  3548. +      awk 'BEGIN {  print "Month Crates"
  3549. +                    print "----- ------" }
  3550. +                 {  print $1, $2 }' inventory-shipped
  3551. + Did you already guess what happens?  This program prints the following:
  3552. +      Month Crates
  3553. +      ----- ------
  3554. +      Jan 13
  3555. +      Feb 15
  3556. +      Mar 15
  3557. +      ...
  3558. + The headings and the table data don't line up!  We can fix this by
  3559. + printing some spaces between the two fields:
  3560. +      awk 'BEGIN { print "Month Crates"
  3561. +                   print "----- ------" }
  3562. +                 { print $1, "     ", $2 }' inventory-shipped
  3563. +    You can imagine that this way of lining up columns can get pretty
  3564. + complicated when you have many columns to fix.  Counting spaces for two
  3565. + or three columns can be simple, but more than this and you can get
  3566. + "lost" quite easily.  This is why the `printf' statement was created
  3567. + (*note Using `printf' Statements for Fancier Printing: Printf.); one of
  3568. + its specialties is lining up columns of data.
  3569. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-3 gawk-2.15.5/gawk.info-3
  3570. *** /src/baseline/gawk-2.15.5/gawk.info-3    Thu Jan  1 00:00:00 1970
  3571. --- gawk-2.15.5/gawk.info-3    Sun Jun 12 22:28:50 1994
  3572. ***************
  3573. *** 0 ****
  3574. --- 1,1288 ----
  3575. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  3576. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  3577. +    This file documents `awk', a program that you can use to select
  3578. + particular records in a file and perform operations upon them.
  3579. +    This is Edition 0.15 of `The GAWK Manual',
  3580. + for the 2.15 version of the GNU implementation
  3581. + of AWK.
  3582. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  3583. +    Permission is granted to make and distribute verbatim copies of this
  3584. + manual provided the copyright notice and this permission notice are
  3585. + preserved on all copies.
  3586. +    Permission is granted to copy and distribute modified versions of
  3587. + this manual under the conditions for verbatim copying, provided that
  3588. + the entire resulting derived work is distributed under the terms of a
  3589. + permission notice identical to this one.
  3590. +    Permission is granted to copy and distribute translations of this
  3591. + manual into another language, under the above conditions for modified
  3592. + versions, except that this permission notice may be stated in a
  3593. + translation approved by the Foundation.
  3594. + 
  3595. + File: gawk.info,  Node: Output Separators,  Next: OFMT,  Prev: Print Examples,  Up: Printing
  3596. + Output Separators
  3597. + =================
  3598. +    As mentioned previously, a `print' statement contains a list of
  3599. + items, separated by commas.  In the output, the items are normally
  3600. + separated by single spaces.  But they do not have to be spaces; a
  3601. + single space is only the default.  You can specify any string of
  3602. + characters to use as the "output field separator" by setting the
  3603. + built-in variable `OFS'.  The initial value of this variable is the
  3604. + string `" "', that is, just a single space.
  3605. +    The output from an entire `print' statement is called an "output
  3606. + record".  Each `print' statement outputs one output record and then
  3607. + outputs a string called the "output record separator".  The built-in
  3608. + variable `ORS' specifies this string.  The initial value of the
  3609. + variable is the string `"\n"' containing a newline character; thus,
  3610. + normally each `print' statement makes a separate line.
  3611. +    You can change how output fields and records are separated by
  3612. + assigning new values to the variables `OFS' and/or `ORS'.  The usual
  3613. + place to do this is in the `BEGIN' rule (*note `BEGIN' and `END'
  3614. + Special Patterns: BEGIN/END.), so that it happens before any input is
  3615. + processed.  You may also do this with assignments on the command line,
  3616. + before the names of your input files.
  3617. +    The following example prints the first and second fields of each
  3618. + input record separated by a semicolon, with a blank line added after
  3619. + each line:
  3620. +      awk 'BEGIN { OFS = ";"; ORS = "\n\n" }
  3621. +                 { print $1, $2 }'  BBS-list
  3622. +    If the value of `ORS' does not contain a newline, all your output
  3623. + will be run together on a single line, unless you output newlines some
  3624. + other way.
  3625. + 
  3626. + File: gawk.info,  Node: OFMT,  Next: Printf,  Prev: Output Separators,  Up: Printing
  3627. + Controlling Numeric Output with `print'
  3628. + =======================================
  3629. +    When you use the `print' statement to print numeric values, `awk'
  3630. + internally converts the number to a string of characters, and prints
  3631. + that string.  `awk' uses the `sprintf' function to do this conversion.
  3632. + For now, it suffices to say that the `sprintf' function accepts a
  3633. + "format specification" that tells it how to format numbers (or
  3634. + strings), and that there are a number of different ways that numbers
  3635. + can be formatted.  The different format specifications are discussed
  3636. + more fully in *Note Using `printf' Statements for Fancier Printing:
  3637. + Printf.
  3638. +    The built-in variable `OFMT' contains the default format
  3639. + specification that `print' uses with `sprintf' when it wants to convert
  3640. + a number to a string for printing.  By supplying different format
  3641. + specifications as the value of `OFMT', you can change how `print' will
  3642. + print your numbers.  As a brief example:
  3643. +      awk 'BEGIN { OFMT = "%d"  # print numbers as integers
  3644. +                   print 17.23 }'
  3645. + will print `17'.
  3646. + 
  3647. + File: gawk.info,  Node: Printf,  Next: Redirection,  Prev: OFMT,  Up: Printing
  3648. + Using `printf' Statements for Fancier Printing
  3649. + ==============================================
  3650. +    If you want more precise control over the output format than `print'
  3651. + gives you, use `printf'.  With `printf' you can specify the width to
  3652. + use for each item, and you can specify various stylistic choices for
  3653. + numbers (such as what radix to use, whether to print an exponent,
  3654. + whether to print a sign, and how many digits to print after the decimal
  3655. + point).  You do this by specifying a string, called the "format
  3656. + string", which controls how and where to print the other arguments.
  3657. + * Menu:
  3658. + * Basic Printf::                Syntax of the `printf' statement.
  3659. + * Control Letters::             Format-control letters.
  3660. + * Format Modifiers::            Format-specification modifiers.
  3661. + * Printf Examples::             Several examples.
  3662. + 
  3663. + File: gawk.info,  Node: Basic Printf,  Next: Control Letters,  Prev: Printf,  Up: Printf
  3664. + Introduction to the `printf' Statement
  3665. + --------------------------------------
  3666. +    The `printf' statement looks like this:
  3667. +      printf FORMAT, ITEM1, ITEM2, ...
  3668. + The entire list of arguments may optionally be enclosed in parentheses.
  3669. + The parentheses are necessary if any of the item expressions uses a
  3670. + relational operator; otherwise it could be confused with a redirection
  3671. + (*note Redirecting Output of `print' and `printf': Redirection.).  The
  3672. + relational operators are `==', `!=', `<', `>', `>=', `<=', `~' and `!~'
  3673. + (*note Comparison Expressions: Comparison Ops.).
  3674. +    The difference between `printf' and `print' is the argument FORMAT.
  3675. + This is an expression whose value is taken as a string; it specifies
  3676. + how to output each of the other arguments.  It is called the "format
  3677. + string".
  3678. +    The format string is the same as in the ANSI C library function
  3679. + `printf'.  Most of FORMAT is text to be output verbatim.  Scattered
  3680. + among this text are "format specifiers", one per item.  Each format
  3681. + specifier says to output the next item at that place in the format.
  3682. +    The `printf' statement does not automatically append a newline to its
  3683. + output.  It outputs only what the format specifies.  So if you want a
  3684. + newline, you must include one in the format.  The output separator
  3685. + variables `OFS' and `ORS' have no effect on `printf' statements.
  3686. + 
  3687. + File: gawk.info,  Node: Control Letters,  Next: Format Modifiers,  Prev: Basic Printf,  Up: Printf
  3688. + Format-Control Letters
  3689. + ----------------------
  3690. +    A format specifier starts with the character `%' and ends with a
  3691. + "format-control letter"; it tells the `printf' statement how to output
  3692. + one item.  (If you actually want to output a `%', write `%%'.)  The
  3693. + format-control letter specifies what kind of value to print.  The rest
  3694. + of the format specifier is made up of optional "modifiers" which are
  3695. + parameters such as the field width to use.
  3696. +    Here is a list of the format-control letters:
  3697. + `c'
  3698. +      This prints a number as an ASCII character.  Thus, `printf "%c",
  3699. +      65' outputs the letter `A'.  The output for a string value is the
  3700. +      first character of the string.
  3701. + `d'
  3702. +      This prints a decimal integer.
  3703. + `i'
  3704. +      This also prints a decimal integer.
  3705. + `e'
  3706. +      This prints a number in scientific (exponential) notation.  For
  3707. +      example,
  3708. +           printf "%4.3e", 1950
  3709. +      prints `1.950e+03', with a total of four significant figures of
  3710. +      which three follow the decimal point.  The `4.3' are "modifiers",
  3711. +      discussed below.
  3712. + `f'
  3713. +      This prints a number in floating point notation.
  3714. + `g'
  3715. +      This prints a number in either scientific notation or floating
  3716. +      point notation, whichever uses fewer characters.
  3717. + `o'
  3718. +      This prints an unsigned octal integer.
  3719. + `s'
  3720. +      This prints a string.
  3721. + `x'
  3722. +      This prints an unsigned hexadecimal integer.
  3723. + `X'
  3724. +      This prints an unsigned hexadecimal integer.  However, for the
  3725. +      values 10 through 15, it uses the letters `A' through `F' instead
  3726. +      of `a' through `f'.
  3727. + `%'
  3728. +      This isn't really a format-control letter, but it does have a
  3729. +      meaning when used after a `%': the sequence `%%' outputs one `%'.
  3730. +      It does not consume an argument.
  3731. + 
  3732. + File: gawk.info,  Node: Format Modifiers,  Next: Printf Examples,  Prev: Control Letters,  Up: Printf
  3733. + Modifiers for `printf' Formats
  3734. + ------------------------------
  3735. +    A format specification can also include "modifiers" that can control
  3736. + how much of the item's value is printed and how much space it gets.  The
  3737. + modifiers come between the `%' and the format-control letter.  Here are
  3738. + the possible modifiers, in the order in which they may appear:
  3739. + `-'
  3740. +      The minus sign, used before the width modifier, says to
  3741. +      left-justify the argument within its specified width.  Normally
  3742. +      the argument is printed right-justified in the specified width.
  3743. +      Thus,
  3744. +           printf "%-4s", "foo"
  3745. +      prints `foo '.
  3746. + `WIDTH'
  3747. +      This is a number representing the desired width of a field.
  3748. +      Inserting any number between the `%' sign and the format control
  3749. +      character forces the field to be expanded to this width.  The
  3750. +      default way to do this is to pad with spaces on the left.  For
  3751. +      example,
  3752. +           printf "%4s", "foo"
  3753. +      prints ` foo'.
  3754. +      The value of WIDTH is a minimum width, not a maximum.  If the item
  3755. +      value requires more than WIDTH characters, it can be as wide as
  3756. +      necessary.  Thus,
  3757. +           printf "%4s", "foobar"
  3758. +      prints `foobar'.
  3759. +      Preceding the WIDTH with a minus sign causes the output to be
  3760. +      padded with spaces on the right, instead of on the left.
  3761. + `.PREC'
  3762. +      This is a number that specifies the precision to use when printing.
  3763. +      This specifies the number of digits you want printed to the right
  3764. +      of the decimal point.  For a string, it specifies the maximum
  3765. +      number of characters from the string that should be printed.
  3766. +    The C library `printf''s dynamic WIDTH and PREC capability (for
  3767. + example, `"%*.*s"') is supported.  Instead of supplying explicit WIDTH
  3768. + and/or PREC values in the format string, you pass them in the argument
  3769. + list.  For example:
  3770. +      w = 5
  3771. +      p = 3
  3772. +      s = "abcdefg"
  3773. +      printf "<%*.*s>\n", w, p, s
  3774. + is exactly equivalent to
  3775. +      s = "abcdefg"
  3776. +      printf "<%5.3s>\n", s
  3777. + Both programs output `<**abc>'.  (We have used the bullet symbol "*" to
  3778. + represent a space, to clearly show you that there are two spaces in the
  3779. + output.)
  3780. +    Earlier versions of `awk' did not support this capability.  You may
  3781. + simulate it by using concatenation to build up the format string, like
  3782. + so:
  3783. +      w = 5
  3784. +      p = 3
  3785. +      s = "abcdefg"
  3786. +      printf "<%" w "." p "s>\n", s
  3787. + This is not particularly easy to read, however.
  3788. + 
  3789. + File: gawk.info,  Node: Printf Examples,  Prev: Format Modifiers,  Up: Printf
  3790. + Examples of Using `printf'
  3791. + --------------------------
  3792. +    Here is how to use `printf' to make an aligned table:
  3793. +      awk '{ printf "%-10s %s\n", $1, $2 }' BBS-list
  3794. + prints the names of bulletin boards (`$1') of the file `BBS-list' as a
  3795. + string of 10 characters, left justified.  It also prints the phone
  3796. + numbers (`$2') afterward on the line.  This produces an aligned
  3797. + two-column table of names and phone numbers:
  3798. +      aardvark   555-5553
  3799. +      alpo-net   555-3412
  3800. +      barfly     555-7685
  3801. +      bites      555-1675
  3802. +      camelot    555-0542
  3803. +      core       555-2912
  3804. +      fooey      555-1234
  3805. +      foot       555-6699
  3806. +      macfoo     555-6480
  3807. +      sdace      555-3430
  3808. +      sabafoo    555-2127
  3809. +    Did you notice that we did not specify that the phone numbers be
  3810. + printed as numbers?  They had to be printed as strings because the
  3811. + numbers are separated by a dash.  This dash would be interpreted as a
  3812. + minus sign if we had tried to print the phone numbers as numbers.  This
  3813. + would have led to some pretty confusing results.
  3814. +    We did not specify a width for the phone numbers because they are the
  3815. + last things on their lines.  We don't need to put spaces after them.
  3816. +    We could make our table look even nicer by adding headings to the
  3817. + tops of the columns.  To do this, use the `BEGIN' pattern (*note
  3818. + `BEGIN' and `END' Special Patterns: BEGIN/END.) to force the header to
  3819. + be printed only once, at the beginning of the `awk' program:
  3820. +      awk 'BEGIN { print "Name      Number"
  3821. +                   print "----      ------" }
  3822. +           { printf "%-10s %s\n", $1, $2 }' BBS-list
  3823. +    Did you notice that we mixed `print' and `printf' statements in the
  3824. + above example?  We could have used just `printf' statements to get the
  3825. + same results:
  3826. +      awk 'BEGIN { printf "%-10s %s\n", "Name", "Number"
  3827. +                   printf "%-10s %s\n", "----", "------" }
  3828. +           { printf "%-10s %s\n", $1, $2 }' BBS-list
  3829. + By outputting each column heading with the same format specification
  3830. + used for the elements of the column, we have made sure that the headings
  3831. + are aligned just like the columns.
  3832. +    The fact that the same format specification is used three times can
  3833. + be emphasized by storing it in a variable, like this:
  3834. +      awk 'BEGIN { format = "%-10s %s\n"
  3835. +                   printf format, "Name", "Number"
  3836. +                   printf format, "----", "------" }
  3837. +           { printf format, $1, $2 }' BBS-list
  3838. +    See if you can use the `printf' statement to line up the headings and
  3839. + table data for our `inventory-shipped' example covered earlier in the
  3840. + section on the `print' statement (*note The `print' Statement: Print.).
  3841. + 
  3842. + File: gawk.info,  Node: Redirection,  Next: Special Files,  Prev: Printf,  Up: Printing
  3843. + Redirecting Output of `print' and `printf'
  3844. + ==========================================
  3845. +    So far we have been dealing only with output that prints to the
  3846. + standard output, usually your terminal.  Both `print' and `printf' can
  3847. + also send their output to other places.  This is called "redirection".
  3848. +    A redirection appears after the `print' or `printf' statement.
  3849. + Redirections in `awk' are written just like redirections in shell
  3850. + commands, except that they are written inside the `awk' program.
  3851. + * Menu:
  3852. + * File/Pipe Redirection::       Redirecting Output to Files and Pipes.
  3853. + * Close Output::                How to close output files and pipes.
  3854. + 
  3855. + File: gawk.info,  Node: File/Pipe Redirection,  Next: Close Output,  Prev: Redirection,  Up: Redirection
  3856. + Redirecting Output to Files and Pipes
  3857. + -------------------------------------
  3858. +    Here are the three forms of output redirection.  They are all shown
  3859. + for the `print' statement, but they work identically for `printf' also.
  3860. + `print ITEMS > OUTPUT-FILE'
  3861. +      This type of redirection prints the items onto the output file
  3862. +      OUTPUT-FILE.  The file name OUTPUT-FILE can be any expression.
  3863. +      Its value is changed to a string and then used as a file name
  3864. +      (*note Expressions as Action Statements: Expressions.).
  3865. +      When this type of redirection is used, the OUTPUT-FILE is erased
  3866. +      before the first output is written to it.  Subsequent writes do not
  3867. +      erase OUTPUT-FILE, but append to it.  If OUTPUT-FILE does not
  3868. +      exist, then it is created.
  3869. +      For example, here is how one `awk' program can write a list of BBS
  3870. +      names to a file `name-list' and a list of phone numbers to a file
  3871. +      `phone-list'.  Each output file contains one name or number per
  3872. +      line.
  3873. +           awk '{ print $2 > "phone-list"
  3874. +                  print $1 > "name-list" }' BBS-list
  3875. + `print ITEMS >> OUTPUT-FILE'
  3876. +      This type of redirection prints the items onto the output file
  3877. +      OUTPUT-FILE.  The difference between this and the single-`>'
  3878. +      redirection is that the old contents (if any) of OUTPUT-FILE are
  3879. +      not erased.  Instead, the `awk' output is appended to the file.
  3880. + `print ITEMS | COMMAND'
  3881. +      It is also possible to send output through a "pipe" instead of
  3882. +      into a file.   This type of redirection opens a pipe to COMMAND
  3883. +      and writes the values of ITEMS through this pipe, to another
  3884. +      process created to execute COMMAND.
  3885. +      The redirection argument COMMAND is actually an `awk' expression.
  3886. +      Its value is converted to a string, whose contents give the shell
  3887. +      command to be run.
  3888. +      For example, this produces two files, one unsorted list of BBS
  3889. +      names and one list sorted in reverse alphabetical order:
  3890. +           awk '{ print $1 > "names.unsorted"
  3891. +                  print $1 | "sort -r > names.sorted" }' BBS-list
  3892. +      Here the unsorted list is written with an ordinary redirection
  3893. +      while the sorted list is written by piping through the `sort'
  3894. +      utility.
  3895. +      Here is an example that uses redirection to mail a message to a
  3896. +      mailing list `bug-system'.  This might be useful when trouble is
  3897. +      encountered in an `awk' script run periodically for system
  3898. +      maintenance.
  3899. +           report = "mail bug-system"
  3900. +           print "Awk script failed:", $0 | report
  3901. +           print "at record number", FNR, "of", FILENAME  | report
  3902. +           close(report)
  3903. +      We call the `close' function here because it's a good idea to close
  3904. +      the pipe as soon as all the intended output has been sent to it.
  3905. +      *Note Closing Output Files and Pipes: Close Output, for more
  3906. +      information on this.  This example also illustrates the use of a
  3907. +      variable to represent a FILE or COMMAND: it is not necessary to
  3908. +      always use a string constant.  Using a variable is generally a
  3909. +      good idea, since `awk' requires you to spell the string value
  3910. +      identically every time.
  3911. +    Redirecting output using `>', `>>', or `|' asks the system to open a
  3912. + file or pipe only if the particular FILE or COMMAND you've specified
  3913. + has not already been written to by your program, or if it has been
  3914. + closed since it was last written to.
  3915. + 
  3916. + File: gawk.info,  Node: Close Output,  Prev: File/Pipe Redirection,  Up: Redirection
  3917. + Closing Output Files and Pipes
  3918. + ------------------------------
  3919. +    When a file or pipe is opened, the file name or command associated
  3920. + with it is remembered by `awk' and subsequent writes to the same file or
  3921. + command are appended to the previous writes.  The file or pipe stays
  3922. + open until `awk' exits.  This is usually convenient.
  3923. +    Sometimes there is a reason to close an output file or pipe earlier
  3924. + than that.  To do this, use the `close' function, as follows:
  3925. +      close(FILENAME)
  3926. + or
  3927. +      close(COMMAND)
  3928. +    The argument FILENAME or COMMAND can be any expression.  Its value
  3929. + must exactly equal the string used to open the file or pipe to begin
  3930. + with--for example, if you open a pipe with this:
  3931. +      print $1 | "sort -r > names.sorted"
  3932. + then you must close it with this:
  3933. +      close("sort -r > names.sorted")
  3934. +    Here are some reasons why you might need to close an output file:
  3935. +    * To write a file and read it back later on in the same `awk'
  3936. +      program.  Close the file when you are finished writing it; then
  3937. +      you can start reading it with `getline' (*note Explicit Input with
  3938. +      `getline': Getline.).
  3939. +    * To write numerous files, successively, in the same `awk' program.
  3940. +      If you don't close the files, eventually you may exceed a system
  3941. +      limit on the number of open files in one process.  So close each
  3942. +      one when you are finished writing it.
  3943. +    * To make a command finish.  When you redirect output through a pipe,
  3944. +      the command reading the pipe normally continues to try to read
  3945. +      input as long as the pipe is open.  Often this means the command
  3946. +      cannot really do its work until the pipe is closed.  For example,
  3947. +      if you redirect output to the `mail' program, the message is not
  3948. +      actually sent until the pipe is closed.
  3949. +    * To run the same program a second time, with the same arguments.
  3950. +      This is not the same thing as giving more input to the first run!
  3951. +      For example, suppose you pipe output to the `mail' program.  If you
  3952. +      output several lines redirected to this pipe without closing it,
  3953. +      they make a single message of several lines.  By contrast, if you
  3954. +      close the pipe after each line of output, then each line makes a
  3955. +      separate message.
  3956. +    `close' returns a value of zero if the close succeeded.  Otherwise,
  3957. + the value will be non-zero.  In this case, `gawk' sets the variable
  3958. + `ERRNO' to a string describing the error that occurred.
  3959. + 
  3960. + File: gawk.info,  Node: Special Files,  Prev: Redirection,  Up: Printing
  3961. + Standard I/O Streams
  3962. + ====================
  3963. +    Running programs conventionally have three input and output streams
  3964. + already available to them for reading and writing.  These are known as
  3965. + the "standard input", "standard output", and "standard error output".
  3966. + These streams are, by default, terminal input and output, but they are
  3967. + often redirected with the shell, via the `<', `<<', `>', `>>', `>&' and
  3968. + `|' operators.  Standard error is used only for writing error messages;
  3969. + the reason we have two separate streams, standard output and standard
  3970. + error, is so that they can be redirected separately.
  3971. +    In other implementations of `awk', the only way to write an error
  3972. + message to standard error in an `awk' program is as follows:
  3973. +      print "Serious error detected!\n" | "cat 1>&2"
  3974. + This works by opening a pipeline to a shell command which can access the
  3975. + standard error stream which it inherits from the `awk' process.  This
  3976. + is far from elegant, and is also inefficient, since it requires a
  3977. + separate process.  So people writing `awk' programs have often
  3978. + neglected to do this.  Instead, they have sent the error messages to the
  3979. + terminal, like this:
  3980. +      NF != 4 {
  3981. +         printf("line %d skipped: doesn't have 4 fields\n", FNR) > "/dev/tty"
  3982. +      }
  3983. + This has the same effect most of the time, but not always: although the
  3984. + standard error stream is usually the terminal, it can be redirected, and
  3985. + when that happens, writing to the terminal is not correct.  In fact, if
  3986. + `awk' is run from a background job, it may not have a terminal at all.
  3987. + Then opening `/dev/tty' will fail.
  3988. +    `gawk' provides special file names for accessing the three standard
  3989. + streams.  When you redirect input or output in `gawk', if the file name
  3990. + matches one of these special names, then `gawk' directly uses the
  3991. + stream it stands for.
  3992. + `/dev/stdin'
  3993. +      The standard input (file descriptor 0).
  3994. + `/dev/stdout'
  3995. +      The standard output (file descriptor 1).
  3996. + `/dev/stderr'
  3997. +      The standard error output (file descriptor 2).
  3998. + `/dev/fd/N'
  3999. +      The file associated with file descriptor N.  Such a file must have
  4000. +      been opened by the program initiating the `awk' execution
  4001. +      (typically the shell).  Unless you take special pains, only
  4002. +      descriptors 0, 1 and 2 are available.
  4003. +    The file names `/dev/stdin', `/dev/stdout', and `/dev/stderr' are
  4004. + aliases for `/dev/fd/0', `/dev/fd/1', and `/dev/fd/2', respectively,
  4005. + but they are more self-explanatory.
  4006. +    The proper way to write an error message in a `gawk' program is to
  4007. + use `/dev/stderr', like this:
  4008. +      NF != 4 {
  4009. +        printf("line %d skipped: doesn't have 4 fields\n", FNR) > "/dev/stderr"
  4010. +      }
  4011. +    `gawk' also provides special file names that give access to
  4012. + information about the running `gawk' process.  Each of these "files"
  4013. + provides a single record of information.  To read them more than once,
  4014. + you must first close them with the `close' function (*note Closing
  4015. + Input Files and Pipes: Close Input.).  The filenames are:
  4016. + `/dev/pid'
  4017. +      Reading this file returns the process ID of the current process,
  4018. +      in decimal, terminated with a newline.
  4019. + `/dev/ppid'
  4020. +      Reading this file returns the parent process ID of the current
  4021. +      process, in decimal, terminated with a newline.
  4022. + `/dev/pgrpid'
  4023. +      Reading this file returns the process group ID of the current
  4024. +      process, in decimal, terminated with a newline.
  4025. + `/dev/user'
  4026. +      Reading this file returns a single record terminated with a
  4027. +      newline.  The fields are separated with blanks.  The fields
  4028. +      represent the following information:
  4029. +     `$1'
  4030. +           The value of the `getuid' system call.
  4031. +     `$2'
  4032. +           The value of the `geteuid' system call.
  4033. +     `$3'
  4034. +           The value of the `getgid' system call.
  4035. +     `$4'
  4036. +           The value of the `getegid' system call.
  4037. +      If there are any additional fields, they are the group IDs
  4038. +      returned by `getgroups' system call.  (Multiple groups may not be
  4039. +      supported on all systems.)
  4040. +    These special file names may be used on the command line as data
  4041. + files, as well as for I/O redirections within an `awk' program.  They
  4042. + may not be used as source files with the `-f' option.
  4043. +    Recognition of these special file names is disabled if `gawk' is in
  4044. + compatibility mode (*note Invoking `awk': Command Line.).
  4045. +      *Caution*:  Unless your system actually has a `/dev/fd' directory
  4046. +      (or any of the other above listed special files), the
  4047. +      interpretation of these file names is done by `gawk' itself.  For
  4048. +      example, using `/dev/fd/4' for output will actually write on file
  4049. +      descriptor 4, and not on a new file descriptor that was `dup''ed
  4050. +      from file descriptor 4.  Most of the time this does not matter;
  4051. +      however, it is important to *not* close any of the files related
  4052. +      to file descriptors 0, 1, and 2.  If you do close one of these
  4053. +      files, unpredictable behavior will result.
  4054. + 
  4055. + File: gawk.info,  Node: One-liners,  Next: Patterns,  Prev: Printing,  Up: Top
  4056. + Useful "One-liners"
  4057. + *******************
  4058. +    Useful `awk' programs are often short, just a line or two.  Here is a
  4059. + collection of useful, short programs to get you started.  Some of these
  4060. + programs contain constructs that haven't been covered yet.  The
  4061. + description of the program will give you a good idea of what is going
  4062. + on, but please read the rest of the manual to become an `awk' expert!
  4063. +    Since you are reading this in Info, each line of the example code is
  4064. + enclosed in quotes, to represent text that you would type literally.
  4065. + The examples themselves represent shell commands that use single quotes
  4066. + to keep the shell from interpreting the contents of the program.  When
  4067. + reading the examples, focus on the text between the open and close
  4068. + quotes.
  4069. + `awk '{ if (NF > max) max = NF }'
  4070. + `     END { print max }''
  4071. +      This program prints the maximum number of fields on any input line.
  4072. + `awk 'length($0) > 80''
  4073. +      This program prints every line longer than 80 characters.  The sole
  4074. +      rule has a relational expression as its pattern, and has no action
  4075. +      (so the default action, printing the record, is used).
  4076. + `awk 'NF > 0''
  4077. +      This program prints every line that has at least one field.  This
  4078. +      is an easy way to delete blank lines from a file (or rather, to
  4079. +      create a new file similar to the old file but from which the blank
  4080. +      lines have been deleted).
  4081. + `awk '{ if (NF > 0) print }''
  4082. +      This program also prints every line that has at least one field.
  4083. +      Here we allow the rule to match every line, then decide in the
  4084. +      action whether to print.
  4085. + `awk 'BEGIN { for (i = 1; i <= 7; i++)'
  4086. + `               print int(101 * rand()) }''
  4087. +      This program prints 7 random numbers from 0 to 100, inclusive.
  4088. + `ls -l FILES | awk '{ x += $4 } ; END { print "total bytes: " x }''
  4089. +      This program prints the total number of bytes used by FILES.
  4090. + `expand FILE | awk '{ if (x < length()) x = length() }'
  4091. + `                  END { print "maximum line length is " x }''
  4092. +      This program prints the maximum line length of FILE.  The input is
  4093. +      piped through the `expand' program to change tabs into spaces, so
  4094. +      the widths compared are actually the right-margin columns.
  4095. + `awk 'BEGIN { FS = ":" }'
  4096. + `     { print $1 | "sort" }' /etc/passwd'
  4097. +      This program prints a sorted list of the login names of all users.
  4098. + `awk '{ nlines++ }'
  4099. + `     END { print nlines }''
  4100. +      This programs counts lines in a file.
  4101. + `awk 'END { print NR }''
  4102. +      This program also counts lines in a file, but lets `awk' do the
  4103. +      work.
  4104. + `awk '{ print NR, $0 }''
  4105. +      This program adds line numbers to all its input files, similar to
  4106. +      `cat -n'.
  4107. + 
  4108. + File: gawk.info,  Node: Patterns,  Next: Actions,  Prev: One-liners,  Up: Top
  4109. + Patterns
  4110. + ********
  4111. +    Patterns in `awk' control the execution of rules: a rule is executed
  4112. + when its pattern matches the current input record.  This chapter tells
  4113. + all about how to write patterns.
  4114. + * Menu:
  4115. + * Kinds of Patterns::           A list of all kinds of patterns.
  4116. +                                 The following subsections describe
  4117. +                                 them in detail.
  4118. + * Regexp::                      Regular expressions such as `/foo/'.
  4119. + * Comparison Patterns::         Comparison expressions such as `$1 > 10'.
  4120. + * Boolean Patterns::            Combining comparison expressions.
  4121. + * Expression Patterns::         Any expression can be used as a pattern.
  4122. + * Ranges::                      Pairs of patterns specify record ranges.
  4123. + * BEGIN/END::                   Specifying initialization and cleanup rules.
  4124. + * Empty::                       The empty pattern, which matches every record.
  4125. + 
  4126. + File: gawk.info,  Node: Kinds of Patterns,  Next: Regexp,  Prev: Patterns,  Up: Patterns
  4127. + Kinds of Patterns
  4128. + =================
  4129. +    Here is a summary of the types of patterns supported in `awk'.
  4130. + `/REGULAR EXPRESSION/'
  4131. +      A regular expression as a pattern.  It matches when the text of the
  4132. +      input record fits the regular expression.  (*Note Regular
  4133. +      Expressions as Patterns: Regexp.)
  4134. + `EXPRESSION'
  4135. +      A single expression.  It matches when its value, converted to a
  4136. +      number, is nonzero (if a number) or nonnull (if a string).  (*Note
  4137. +      Expressions as Patterns: Expression Patterns.)
  4138. + `PAT1, PAT2'
  4139. +      A pair of patterns separated by a comma, specifying a range of
  4140. +      records.  (*Note Specifying Record Ranges with Patterns: Ranges.)
  4141. + `BEGIN'
  4142. + `END'
  4143. +      Special patterns to supply start-up or clean-up information to
  4144. +      `awk'.  (*Note `BEGIN' and `END' Special Patterns: BEGIN/END.)
  4145. + `NULL'
  4146. +      The empty pattern matches every input record.  (*Note The Empty
  4147. +      Pattern: Empty.)
  4148. + 
  4149. + File: gawk.info,  Node: Regexp,  Next: Comparison Patterns,  Prev: Kinds of Patterns,  Up: Patterns
  4150. + Regular Expressions as Patterns
  4151. + ===============================
  4152. +    A "regular expression", or "regexp", is a way of describing a class
  4153. + of strings.  A regular expression enclosed in slashes (`/') is an `awk'
  4154. + pattern that matches every input record whose text belongs to that
  4155. + class.
  4156. +    The simplest regular expression is a sequence of letters, numbers, or
  4157. + both.  Such a regexp matches any string that contains that sequence.
  4158. + Thus, the regexp `foo' matches any string containing `foo'.  Therefore,
  4159. + the pattern `/foo/' matches any input record containing `foo'.  Other
  4160. + kinds of regexps let you specify more complicated classes of strings.
  4161. + * Menu:
  4162. + * Regexp Usage::                How to Use Regular Expressions
  4163. + * Regexp Operators::            Regular Expression Operators
  4164. + * Case-sensitivity::            How to do case-insensitive matching.
  4165. + 
  4166. + File: gawk.info,  Node: Regexp Usage,  Next: Regexp Operators,  Prev: Regexp,  Up: Regexp
  4167. + How to Use Regular Expressions
  4168. + ------------------------------
  4169. +    A regular expression can be used as a pattern by enclosing it in
  4170. + slashes.  Then the regular expression is matched against the entire
  4171. + text of each record.  (Normally, it only needs to match some part of
  4172. + the text in order to succeed.)  For example, this prints the second
  4173. + field of each record that contains `foo' anywhere:
  4174. +      awk '/foo/ { print $2 }' BBS-list
  4175. +    Regular expressions can also be used in comparison expressions.  Then
  4176. + you can specify the string to match against; it need not be the entire
  4177. + current input record.  These comparison expressions can be used as
  4178. + patterns or in `if', `while', `for', and `do' statements.
  4179. + `EXP ~ /REGEXP/'
  4180. +      This is true if the expression EXP (taken as a character string)
  4181. +      is matched by REGEXP.  The following example matches, or selects,
  4182. +      all input records with the upper-case letter `J' somewhere in the
  4183. +      first field:
  4184. +           awk '$1 ~ /J/' inventory-shipped
  4185. +      So does this:
  4186. +           awk '{ if ($1 ~ /J/) print }' inventory-shipped
  4187. + `EXP !~ /REGEXP/'
  4188. +      This is true if the expression EXP (taken as a character string)
  4189. +      is *not* matched by REGEXP.  The following example matches, or
  4190. +      selects, all input records whose first field *does not* contain
  4191. +      the upper-case letter `J':
  4192. +           awk '$1 !~ /J/' inventory-shipped
  4193. +    The right hand side of a `~' or `!~' operator need not be a constant
  4194. + regexp (i.e., a string of characters between slashes).  It may be any
  4195. + expression.  The expression is evaluated, and converted if necessary to
  4196. + a string; the contents of the string are used as the regexp.  A regexp
  4197. + that is computed in this way is called a "dynamic regexp".  For example:
  4198. +      identifier_regexp = "[A-Za-z_][A-Za-z_0-9]+"
  4199. +      $0 ~ identifier_regexp
  4200. + sets `identifier_regexp' to a regexp that describes `awk' variable
  4201. + names, and tests if the input record matches this regexp.
  4202. + 
  4203. + File: gawk.info,  Node: Regexp Operators,  Next: Case-sensitivity,  Prev: Regexp Usage,  Up: Regexp
  4204. + Regular Expression Operators
  4205. + ----------------------------
  4206. +    You can combine regular expressions with the following characters,
  4207. + called "regular expression operators", or "metacharacters", to increase
  4208. + the power and versatility of regular expressions.
  4209. +    Here is a table of metacharacters.  All characters not listed in the
  4210. + table stand for themselves.
  4211. + `^'
  4212. +      This matches the beginning of the string or the beginning of a line
  4213. +      within the string.  For example:
  4214. +           ^@chapter
  4215. +      matches the `@chapter' at the beginning of a string, and can be
  4216. +      used to identify chapter beginnings in Texinfo source files.
  4217. + `$'
  4218. +      This is similar to `^', but it matches only at the end of a string
  4219. +      or the end of a line within the string.  For example:
  4220. +           p$
  4221. +      matches a record that ends with a `p'.
  4222. + `.'
  4223. +      This matches any single character except a newline.  For example:
  4224. +           .P
  4225. +      matches any single character followed by a `P' in a string.  Using
  4226. +      concatenation we can make regular expressions like `U.A', which
  4227. +      matches any three-character sequence that begins with `U' and ends
  4228. +      with `A'.
  4229. + `[...]'
  4230. +      This is called a "character set".  It matches any one of the
  4231. +      characters that are enclosed in the square brackets.  For example:
  4232. +           [MVX]
  4233. +      matches any one of the characters `M', `V', or `X' in a string.
  4234. +      Ranges of characters are indicated by using a hyphen between the
  4235. +      beginning and ending characters, and enclosing the whole thing in
  4236. +      brackets.  For example:
  4237. +           [0-9]
  4238. +      matches any digit.
  4239. +      To include the character `\', `]', `-' or `^' in a character set,
  4240. +      put a `\' in front of it.  For example:
  4241. +           [d\]]
  4242. +      matches either `d', or `]'.
  4243. +      This treatment of `\' is compatible with other `awk'
  4244. +      implementations, and is also mandated by the POSIX Command Language
  4245. +      and Utilities standard.  The regular expressions in `awk' are a
  4246. +      superset of the POSIX specification for Extended Regular
  4247. +      Expressions (EREs).  POSIX EREs are based on the regular
  4248. +      expressions accepted by the traditional `egrep' utility.
  4249. +      In `egrep' syntax, backslash is not syntactically special within
  4250. +      square brackets.  This means that special tricks have to be used to
  4251. +      represent the characters `]', `-' and `^' as members of a
  4252. +      character set.
  4253. +      In `egrep' syntax, to match `-', write it as `---', which is a
  4254. +      range containing only `-'.  You may also give `-' as the first or
  4255. +      last character in the set.  To match `^', put it anywhere except
  4256. +      as the first character of a set.  To match a `]', make it the
  4257. +      first character in the set.  For example:
  4258. +           []d^]
  4259. +      matches either `]', `d' or `^'.
  4260. + `[^ ...]'
  4261. +      This is a "complemented character set".  The first character after
  4262. +      the `[' *must* be a `^'.  It matches any characters *except* those
  4263. +      in the square brackets (or newline).  For example:
  4264. +           [^0-9]
  4265. +      matches any character that is not a digit.
  4266. + `|'
  4267. +      This is the "alternation operator" and it is used to specify
  4268. +      alternatives.  For example:
  4269. +           ^P|[0-9]
  4270. +      matches any string that matches either `^P' or `[0-9]'.  This
  4271. +      means it matches any string that contains a digit or starts with
  4272. +      `P'.
  4273. +      The alternation applies to the largest possible regexps on either
  4274. +      side.
  4275. + `(...)'
  4276. +      Parentheses are used for grouping in regular expressions as in
  4277. +      arithmetic.  They can be used to concatenate regular expressions
  4278. +      containing the alternation operator, `|'.
  4279. + `*'
  4280. +      This symbol means that the preceding regular expression is to be
  4281. +      repeated as many times as possible to find a match.  For example:
  4282. +           ph*
  4283. +      applies the `*' symbol to the preceding `h' and looks for matches
  4284. +      to one `p' followed by any number of `h's.  This will also match
  4285. +      just `p' if no `h's are present.
  4286. +      The `*' repeats the *smallest* possible preceding expression.
  4287. +      (Use parentheses if you wish to repeat a larger expression.)  It
  4288. +      finds as many repetitions as possible.  For example:
  4289. +           awk '/\(c[ad][ad]*r x\)/ { print }' sample
  4290. +      prints every record in the input containing a string of the form
  4291. +      `(car x)', `(cdr x)', `(cadr x)', and so on.
  4292. + `+'
  4293. +      This symbol is similar to `*', but the preceding expression must be
  4294. +      matched at least once.  This means that:
  4295. +           wh+y
  4296. +      would match `why' and `whhy' but not `wy', whereas `wh*y' would
  4297. +      match all three of these strings.  This is a simpler way of
  4298. +      writing the last `*' example:
  4299. +           awk '/\(c[ad]+r x\)/ { print }' sample
  4300. + `?'
  4301. +      This symbol is similar to `*', but the preceding expression can be
  4302. +      matched once or not at all.  For example:
  4303. +           fe?d
  4304. +      will match `fed' and `fd', but nothing else.
  4305. + `\'
  4306. +      This is used to suppress the special meaning of a character when
  4307. +      matching.  For example:
  4308. +           \$
  4309. +      matches the character `$'.
  4310. +      The escape sequences used for string constants (*note Constant
  4311. +      Expressions: Constants.) are valid in regular expressions as well;
  4312. +      they are also introduced by a `\'.
  4313. +    In regular expressions, the `*', `+', and `?' operators have the
  4314. + highest precedence, followed by concatenation, and finally by `|'.  As
  4315. + in arithmetic, parentheses can change how operators are grouped.
  4316. + 
  4317. + File: gawk.info,  Node: Case-sensitivity,  Prev: Regexp Operators,  Up: Regexp
  4318. + Case-sensitivity in Matching
  4319. + ----------------------------
  4320. +    Case is normally significant in regular expressions, both when
  4321. + matching ordinary characters (i.e., not metacharacters), and inside
  4322. + character sets.  Thus a `w' in a regular expression matches only a
  4323. + lower case `w' and not an upper case `W'.
  4324. +    The simplest way to do a case-independent match is to use a character
  4325. + set: `[Ww]'.  However, this can be cumbersome if you need to use it
  4326. + often; and it can make the regular expressions harder for humans to
  4327. + read.  There are two other alternatives that you might prefer.
  4328. +    One way to do a case-insensitive match at a particular point in the
  4329. + program is to convert the data to a single case, using the `tolower' or
  4330. + `toupper' built-in string functions (which we haven't discussed yet;
  4331. + *note Built-in Functions for String Manipulation: String Functions.).
  4332. + For example:
  4333. +      tolower($1) ~ /foo/  { ... }
  4334. + converts the first field to lower case before matching against it.
  4335. +    Another method is to set the variable `IGNORECASE' to a nonzero
  4336. + value (*note Built-in Variables::.).  When `IGNORECASE' is not zero,
  4337. + *all* regexp operations ignore case.  Changing the value of
  4338. + `IGNORECASE' dynamically controls the case sensitivity of your program
  4339. + as it runs.  Case is significant by default because `IGNORECASE' (like
  4340. + most variables) is initialized to zero.
  4341. +      x = "aB"
  4342. +      if (x ~ /ab/) ...   # this test will fail
  4343. +      
  4344. +      IGNORECASE = 1
  4345. +      if (x ~ /ab/) ...   # now it will succeed
  4346. +    In general, you cannot use `IGNORECASE' to make certain rules
  4347. + case-insensitive and other rules case-sensitive, because there is no way
  4348. + to set `IGNORECASE' just for the pattern of a particular rule.  To do
  4349. + this, you must use character sets or `tolower'.  However, one thing you
  4350. + can do only with `IGNORECASE' is turn case-sensitivity on or off
  4351. + dynamically for all the rules at once.
  4352. +    `IGNORECASE' can be set on the command line, or in a `BEGIN' rule.
  4353. + Setting `IGNORECASE' from the command line is a way to make a program
  4354. + case-insensitive without having to edit it.
  4355. +    The value of `IGNORECASE' has no effect if `gawk' is in
  4356. + compatibility mode (*note Invoking `awk': Command Line.).  Case is
  4357. + always significant in compatibility mode.
  4358. + 
  4359. + File: gawk.info,  Node: Comparison Patterns,  Next: Boolean Patterns,  Prev: Regexp,  Up: Patterns
  4360. + Comparison Expressions as Patterns
  4361. + ==================================
  4362. +    "Comparison patterns" test relationships such as equality between
  4363. + two strings or numbers.  They are a special case of expression patterns
  4364. + (*note Expressions as Patterns: Expression Patterns.).  They are written
  4365. + with "relational operators", which are a superset of those in C.  Here
  4366. + is a table of them:
  4367. + `X < Y'
  4368. +      True if X is less than Y.
  4369. + `X <= Y'
  4370. +      True if X is less than or equal to Y.
  4371. + `X > Y'
  4372. +      True if X is greater than Y.
  4373. + `X >= Y'
  4374. +      True if X is greater than or equal to Y.
  4375. + `X == Y'
  4376. +      True if X is equal to Y.
  4377. + `X != Y'
  4378. +      True if X is not equal to Y.
  4379. + `X ~ Y'
  4380. +      True if X matches the regular expression described by Y.
  4381. + `X !~ Y'
  4382. +      True if X does not match the regular expression described by Y.
  4383. +    The operands of a relational operator are compared as numbers if they
  4384. + are both numbers.  Otherwise they are converted to, and compared as,
  4385. + strings (*note Conversion of Strings and Numbers: Conversion., for the
  4386. + detailed rules).  Strings are compared by comparing the first character
  4387. + of each, then the second character of each, and so on, until there is a
  4388. + difference.  If the two strings are equal until the shorter one runs
  4389. + out, the shorter one is considered to be less than the longer one.
  4390. + Thus, `"10"' is less than `"9"', and `"abc"' is less than `"abcd"'.
  4391. +    The left operand of the `~' and `!~' operators is a string.  The
  4392. + right operand is either a constant regular expression enclosed in
  4393. + slashes (`/REGEXP/'), or any expression, whose string value is used as
  4394. + a dynamic regular expression (*note How to Use Regular Expressions:
  4395. + Regexp Usage.).
  4396. +    The following example prints the second field of each input record
  4397. + whose first field is precisely `foo'.
  4398. +      awk '$1 == "foo" { print $2 }' BBS-list
  4399. + Contrast this with the following regular expression match, which would
  4400. + accept any record with a first field that contains `foo':
  4401. +      awk '$1 ~ "foo" { print $2 }' BBS-list
  4402. + or, equivalently, this one:
  4403. +      awk '$1 ~ /foo/ { print $2 }' BBS-list
  4404. + 
  4405. + File: gawk.info,  Node: Boolean Patterns,  Next: Expression Patterns,  Prev: Comparison Patterns,  Up: Patterns
  4406. + Boolean Operators and Patterns
  4407. + ==============================
  4408. +    A "boolean pattern" is an expression which combines other patterns
  4409. + using the "boolean operators" "or" (`||'), "and" (`&&'), and "not"
  4410. + (`!').  Whether the boolean pattern matches an input record depends on
  4411. + whether its subpatterns match.
  4412. +    For example, the following command prints all records in the input
  4413. + file `BBS-list' that contain both `2400' and `foo'.
  4414. +      awk '/2400/ && /foo/' BBS-list
  4415. +    The following command prints all records in the input file
  4416. + `BBS-list' that contain *either* `2400' or `foo', or both.
  4417. +      awk '/2400/ || /foo/' BBS-list
  4418. +    The following command prints all records in the input file
  4419. + `BBS-list' that do *not* contain the string `foo'.
  4420. +      awk '! /foo/' BBS-list
  4421. +    Note that boolean patterns are a special case of expression patterns
  4422. + (*note Expressions as Patterns: Expression Patterns.); they are
  4423. + expressions that use the boolean operators.  *Note Boolean Expressions:
  4424. + Boolean Ops, for complete information on the boolean operators.
  4425. +    The subpatterns of a boolean pattern can be constant regular
  4426. + expressions, comparisons, or any other `awk' expressions.  Range
  4427. + patterns are not expressions, so they cannot appear inside boolean
  4428. + patterns.  Likewise, the special patterns `BEGIN' and `END', which
  4429. + never match any input record, are not expressions and cannot appear
  4430. + inside boolean patterns.
  4431. + 
  4432. + File: gawk.info,  Node: Expression Patterns,  Next: Ranges,  Prev: Boolean Patterns,  Up: Patterns
  4433. + Expressions as Patterns
  4434. + =======================
  4435. +    Any `awk' expression is also valid as an `awk' pattern.  Then the
  4436. + pattern "matches" if the expression's value is nonzero (if a number) or
  4437. + nonnull (if a string).
  4438. +    The expression is reevaluated each time the rule is tested against a
  4439. + new input record.  If the expression uses fields such as `$1', the
  4440. + value depends directly on the new input record's text; otherwise, it
  4441. + depends only on what has happened so far in the execution of the `awk'
  4442. + program, but that may still be useful.
  4443. +    Comparison patterns are actually a special case of this.  For
  4444. + example, the expression `$5 == "foo"' has the value 1 when the value of
  4445. + `$5' equals `"foo"', and 0 otherwise; therefore, this expression as a
  4446. + pattern matches when the two values are equal.
  4447. +    Boolean patterns are also special cases of expression patterns.
  4448. +    A constant regexp as a pattern is also a special case of an
  4449. + expression pattern.  `/foo/' as an expression has the value 1 if `foo'
  4450. + appears in the current input record; thus, as a pattern, `/foo/'
  4451. + matches any record containing `foo'.
  4452. +    Other implementations of `awk' that are not yet POSIX compliant are
  4453. + less general than `gawk': they allow comparison expressions, and
  4454. + boolean combinations thereof (optionally with parentheses), but not
  4455. + necessarily other kinds of expressions.
  4456. + 
  4457. + File: gawk.info,  Node: Ranges,  Next: BEGIN/END,  Prev: Expression Patterns,  Up: Patterns
  4458. + Specifying Record Ranges with Patterns
  4459. + ======================================
  4460. +    A "range pattern" is made of two patterns separated by a comma, of
  4461. + the form `BEGPAT, ENDPAT'.  It matches ranges of consecutive input
  4462. + records.  The first pattern BEGPAT controls where the range begins, and
  4463. + the second one ENDPAT controls where it ends.  For example,
  4464. +      awk '$1 == "on", $1 == "off"'
  4465. + prints every record between `on'/`off' pairs, inclusive.
  4466. +    A range pattern starts out by matching BEGPAT against every input
  4467. + record; when a record matches BEGPAT, the range pattern becomes "turned
  4468. + on".  The range pattern matches this record.  As long as it stays
  4469. + turned on, it automatically matches every input record read.  It also
  4470. + matches ENDPAT against every input record; when that succeeds, the
  4471. + range pattern is turned off again for the following record.  Now it
  4472. + goes back to checking BEGPAT against each record.
  4473. +    The record that turns on the range pattern and the one that turns it
  4474. + off both match the range pattern.  If you don't want to operate on
  4475. + these records, you can write `if' statements in the rule's action to
  4476. + distinguish them.
  4477. +    It is possible for a pattern to be turned both on and off by the same
  4478. + record, if both conditions are satisfied by that record.  Then the
  4479. + action is executed for just that record.
  4480. + 
  4481. + File: gawk.info,  Node: BEGIN/END,  Next: Empty,  Prev: Ranges,  Up: Patterns
  4482. + `BEGIN' and `END' Special Patterns
  4483. + ==================================
  4484. +    `BEGIN' and `END' are special patterns.  They are not used to match
  4485. + input records.  Rather, they are used for supplying start-up or
  4486. + clean-up information to your `awk' script.  A `BEGIN' rule is executed,
  4487. + once, before the first input record has been read.  An `END' rule is
  4488. + executed, once, after all the input has been read.  For example:
  4489. +      awk 'BEGIN { print "Analysis of `foo'" }
  4490. +           /foo/ { ++foobar }
  4491. +           END   { print "`foo' appears " foobar " times." }' BBS-list
  4492. +    This program finds the number of records in the input file `BBS-list'
  4493. + that contain the string `foo'.  The `BEGIN' rule prints a title for the
  4494. + report.  There is no need to use the `BEGIN' rule to initialize the
  4495. + counter `foobar' to zero, as `awk' does this for us automatically
  4496. + (*note Variables::.).
  4497. +    The second rule increments the variable `foobar' every time a record
  4498. + containing the pattern `foo' is read.  The `END' rule prints the value
  4499. + of `foobar' at the end of the run.
  4500. +    The special patterns `BEGIN' and `END' cannot be used in ranges or
  4501. + with boolean operators (indeed, they cannot be used with any operators).
  4502. +    An `awk' program may have multiple `BEGIN' and/or `END' rules.  They
  4503. + are executed in the order they appear, all the `BEGIN' rules at
  4504. + start-up and all the `END' rules at termination.
  4505. +    Multiple `BEGIN' and `END' sections are useful for writing library
  4506. + functions, since each library can have its own `BEGIN' or `END' rule to
  4507. + do its own initialization and/or cleanup.  Note that the order in which
  4508. + library functions are named on the command line controls the order in
  4509. + which their `BEGIN' and `END' rules are executed.  Therefore you have
  4510. + to be careful to write such rules in library files so that the order in
  4511. + which they are executed doesn't matter.  *Note Invoking `awk': Command
  4512. + Line, for more information on using library functions.
  4513. +    If an `awk' program only has a `BEGIN' rule, and no other rules,
  4514. + then the program exits after the `BEGIN' rule has been run.  (Older
  4515. + versions of `awk' used to keep reading and ignoring input until end of
  4516. + file was seen.)  However, if an `END' rule exists as well, then the
  4517. + input will be read, even if there are no other rules in the program.
  4518. + This is necessary in case the `END' rule checks the `NR' variable.
  4519. +    `BEGIN' and `END' rules must have actions; there is no default
  4520. + action for these rules since there is no current record when they run.
  4521. + 
  4522. + File: gawk.info,  Node: Empty,  Prev: BEGIN/END,  Up: Patterns
  4523. + The Empty Pattern
  4524. + =================
  4525. +    An empty pattern is considered to match *every* input record.  For
  4526. + example, the program:
  4527. +      awk '{ print $1 }' BBS-list
  4528. + prints the first field of every record.
  4529. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-4 gawk-2.15.5/gawk.info-4
  4530. *** /src/baseline/gawk-2.15.5/gawk.info-4    Thu Jan  1 00:00:00 1970
  4531. --- gawk-2.15.5/gawk.info-4    Sun Jun 12 22:28:51 1994
  4532. ***************
  4533. *** 0 ****
  4534. --- 1,1305 ----
  4535. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  4536. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  4537. +    This file documents `awk', a program that you can use to select
  4538. + particular records in a file and perform operations upon them.
  4539. +    This is Edition 0.15 of `The GAWK Manual',
  4540. + for the 2.15 version of the GNU implementation
  4541. + of AWK.
  4542. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  4543. +    Permission is granted to make and distribute verbatim copies of this
  4544. + manual provided the copyright notice and this permission notice are
  4545. + preserved on all copies.
  4546. +    Permission is granted to copy and distribute modified versions of
  4547. + this manual under the conditions for verbatim copying, provided that
  4548. + the entire resulting derived work is distributed under the terms of a
  4549. + permission notice identical to this one.
  4550. +    Permission is granted to copy and distribute translations of this
  4551. + manual into another language, under the above conditions for modified
  4552. + versions, except that this permission notice may be stated in a
  4553. + translation approved by the Foundation.
  4554. + 
  4555. + File: gawk.info,  Node: Actions,  Next: Expressions,  Prev: Patterns,  Up: Top
  4556. + Overview of Actions
  4557. + *******************
  4558. +    An `awk' program or script consists of a series of rules and
  4559. + function definitions, interspersed.  (Functions are described later.
  4560. + *Note User-defined Functions: User-defined.)
  4561. +    A rule contains a pattern and an action, either of which may be
  4562. + omitted.  The purpose of the "action" is to tell `awk' what to do once
  4563. + a match for the pattern is found.  Thus, the entire program looks
  4564. + somewhat like this:
  4565. +      [PATTERN] [{ ACTION }]
  4566. +      [PATTERN] [{ ACTION }]
  4567. +      ...
  4568. +      function NAME (ARGS) { ... }
  4569. +      ...
  4570. +    An action consists of one or more `awk' "statements", enclosed in
  4571. + curly braces (`{' and `}').  Each statement specifies one thing to be
  4572. + done.  The statements are separated by newlines or semicolons.
  4573. +    The curly braces around an action must be used even if the action
  4574. + contains only one statement, or even if it contains no statements at
  4575. + all.  However, if you omit the action entirely, omit the curly braces as
  4576. + well.  (An omitted action is equivalent to `{ print $0 }'.)
  4577. +    Here are the kinds of statements supported in `awk':
  4578. +    * Expressions, which can call functions or assign values to variables
  4579. +      (*note Expressions as Action Statements: Expressions.).  Executing
  4580. +      this kind of statement simply computes the value of the expression
  4581. +      and then ignores it.  This is useful when the expression has side
  4582. +      effects (*note Assignment Expressions: Assignment Ops.).
  4583. +    * Control statements, which specify the control flow of `awk'
  4584. +      programs.  The `awk' language gives you C-like constructs (`if',
  4585. +      `for', `while', and so on) as well as a few special ones (*note
  4586. +      Control Statements in Actions: Statements.).
  4587. +    * Compound statements, which consist of one or more statements
  4588. +      enclosed in curly braces.  A compound statement is used in order
  4589. +      to put several statements together in the body of an `if',
  4590. +      `while', `do' or `for' statement.
  4591. +    * Input control, using the `getline' command (*note Explicit Input
  4592. +      with `getline': Getline.), and the `next' statement (*note The
  4593. +      `next' Statement: Next Statement.).
  4594. +    * Output statements, `print' and `printf'.  *Note Printing Output:
  4595. +      Printing.
  4596. +    * Deletion statements, for deleting array elements.  *Note The
  4597. +      `delete' Statement: Delete.
  4598. + 
  4599. + File: gawk.info,  Node: Expressions,  Next: Statements,  Prev: Actions,  Up: Top
  4600. + Expressions as Action Statements
  4601. + ********************************
  4602. +    Expressions are the basic building block of `awk' actions.  An
  4603. + expression evaluates to a value, which you can print, test, store in a
  4604. + variable or pass to a function.  But beyond that, an expression can
  4605. + assign a new value to a variable or a field, with an assignment
  4606. + operator.
  4607. +    An expression can serve as a statement on its own.  Most other kinds
  4608. + of statements contain one or more expressions which specify data to be
  4609. + operated on.  As in other languages, expressions in `awk' include
  4610. + variables, array references, constants, and function calls, as well as
  4611. + combinations of these with various operators.
  4612. + * Menu:
  4613. + * Constants::                   String, numeric, and regexp constants.
  4614. + * Variables::                   Variables give names to values for later use.
  4615. + * Arithmetic Ops::              Arithmetic operations (`+', `-', etc.)
  4616. + * Concatenation::               Concatenating strings.
  4617. + * Comparison Ops::              Comparison of numbers and strings
  4618. +                                 with `<', etc.
  4619. + * Boolean Ops::                 Combining comparison expressions
  4620. +                                 using boolean operators
  4621. +                                 `||' ("or"), `&&' ("and") and `!' ("not").
  4622. + * Assignment Ops::              Changing the value of a variable or a field.
  4623. + * Increment Ops::               Incrementing the numeric value of a variable.
  4624. + * Conversion::                  The conversion of strings to numbers
  4625. +                                 and vice versa.
  4626. + * Values::                      The whole truth about numbers and strings.
  4627. + * Conditional Exp::             Conditional expressions select
  4628. +                                 between two subexpressions under control
  4629. +                                 of a third subexpression.
  4630. + * Function Calls::              A function call is an expression.
  4631. + * Precedence::                  How various operators nest.
  4632. + 
  4633. + File: gawk.info,  Node: Constants,  Next: Variables,  Prev: Expressions,  Up: Expressions
  4634. + Constant Expressions
  4635. + ====================
  4636. +    The simplest type of expression is the "constant", which always has
  4637. + the same value.  There are three types of constants: numeric constants,
  4638. + string constants, and regular expression constants.
  4639. +    A "numeric constant" stands for a number.  This number can be an
  4640. + integer, a decimal fraction, or a number in scientific (exponential)
  4641. + notation.  Note that all numeric values are represented within `awk' in
  4642. + double-precision floating point.  Here are some examples of numeric
  4643. + constants, which all have the same value:
  4644. +      105
  4645. +      1.05e+2
  4646. +      1050e-1
  4647. +    A string constant consists of a sequence of characters enclosed in
  4648. + double-quote marks.  For example:
  4649. +      "parrot"
  4650. + represents the string whose contents are `parrot'.  Strings in `gawk'
  4651. + can be of any length and they can contain all the possible 8-bit ASCII
  4652. + characters including ASCII NUL.  Other `awk' implementations may have
  4653. + difficulty with some character codes.
  4654. +    Some characters cannot be included literally in a string constant.
  4655. + You represent them instead with "escape sequences", which are character
  4656. + sequences beginning with a backslash (`\').
  4657. +    One use of an escape sequence is to include a double-quote character
  4658. + in a string constant.  Since a plain double-quote would end the string,
  4659. + you must use `\"' to represent a single double-quote character as a
  4660. + part of the string.  The backslash character itself is another
  4661. + character that cannot be included normally; you write `\\' to put one
  4662. + backslash in the string.  Thus, the string whose contents are the two
  4663. + characters `"\' must be written `"\"\\"'.
  4664. +    Another use of backslash is to represent unprintable characters such
  4665. + as newline.  While there is nothing to stop you from writing most of
  4666. + these characters directly in a string constant, they may look ugly.
  4667. +    Here is a table of all the escape sequences used in `awk':
  4668. + `\\'
  4669. +      Represents a literal backslash, `\'.
  4670. + `\a'
  4671. +      Represents the "alert" character, control-g, ASCII code 7.
  4672. + `\b'
  4673. +      Represents a backspace, control-h, ASCII code 8.
  4674. + `\f'
  4675. +      Represents a formfeed, control-l, ASCII code 12.
  4676. + `\n'
  4677. +      Represents a newline, control-j, ASCII code 10.
  4678. + `\r'
  4679. +      Represents a carriage return, control-m, ASCII code 13.
  4680. + `\t'
  4681. +      Represents a horizontal tab, control-i, ASCII code 9.
  4682. + `\v'
  4683. +      Represents a vertical tab, control-k, ASCII code 11.
  4684. + `\NNN'
  4685. +      Represents the octal value NNN, where NNN are one to three digits
  4686. +      between 0 and 7.  For example, the code for the ASCII ESC (escape)
  4687. +      character is `\033'.
  4688. + `\xHH...'
  4689. +      Represents the hexadecimal value HH, where HH are hexadecimal
  4690. +      digits (`0' through `9' and either `A' through `F' or `a' through
  4691. +      `f').  Like the same construct in ANSI C, the escape sequence
  4692. +      continues until the first non-hexadecimal digit is seen.  However,
  4693. +      using more than two hexadecimal digits produces undefined results.
  4694. +      (The `\x' escape sequence is not allowed in POSIX `awk'.)
  4695. +    A "constant regexp" is a regular expression description enclosed in
  4696. + slashes, such as `/^beginning and end$/'.  Most regexps used in `awk'
  4697. + programs are constant, but the `~' and `!~' operators can also match
  4698. + computed or "dynamic" regexps (*note How to Use Regular Expressions:
  4699. + Regexp Usage.).
  4700. +    Constant regexps may be used like simple expressions.  When a
  4701. + constant regexp is not on the right hand side of the `~' or `!~'
  4702. + operators, it has the same meaning as if it appeared in a pattern, i.e.
  4703. + `($0 ~ /foo/)' (*note Expressions as Patterns: Expression Patterns.).
  4704. + This means that the two code segments,
  4705. +      if ($0 ~ /barfly/ || $0 ~ /camelot/)
  4706. +          print "found"
  4707. + and
  4708. +      if (/barfly/ || /camelot/)
  4709. +          print "found"
  4710. + are exactly equivalent.  One rather bizarre consequence of this rule is
  4711. + that the following boolean expression is legal, but does not do what
  4712. + the user intended:
  4713. +      if (/foo/ ~ $1) print "found foo"
  4714. +    This code is "obviously" testing `$1' for a match against the regexp
  4715. + `/foo/'.  But in fact, the expression `(/foo/ ~ $1)' actually means
  4716. + `(($0 ~ /foo/) ~ $1)'.  In other words, first match the input record
  4717. + against the regexp `/foo/'.  The result will be either a 0 or a 1,
  4718. + depending upon the success or failure of the match.  Then match that
  4719. + result against the first field in the record.
  4720. +    Since it is unlikely that you would ever really wish to make this
  4721. + kind of test, `gawk' will issue a warning when it sees this construct in
  4722. + a program.
  4723. +    Another consequence of this rule is that the assignment statement
  4724. +      matches = /foo/
  4725. + will assign either 0 or 1 to the variable `matches', depending upon the
  4726. + contents of the current input record.
  4727. +    Constant regular expressions are also used as the first argument for
  4728. + the `sub' and `gsub' functions (*note Built-in Functions for String
  4729. + Manipulation: String Functions.).
  4730. +    This feature of the language was never well documented until the
  4731. + POSIX specification.
  4732. +    You may be wondering, when is
  4733. +      $1 ~ /foo/ { ... }
  4734. + preferable to
  4735. +      $1 ~ "foo" { ... }
  4736. +    Since the right-hand sides of both `~' operators are constants, it
  4737. + is more efficient to use the `/foo/' form: `awk' can note that you have
  4738. + supplied a regexp and store it internally in a form that makes pattern
  4739. + matching more efficient.  In the second form, `awk' must first convert
  4740. + the string into this internal form, and then perform the pattern
  4741. + matching.  The first form is also better style; it shows clearly that
  4742. + you intend a regexp match.
  4743. + 
  4744. + File: gawk.info,  Node: Variables,  Next: Arithmetic Ops,  Prev: Constants,  Up: Expressions
  4745. + Variables
  4746. + =========
  4747. +    Variables let you give names to values and refer to them later.  You
  4748. + have already seen variables in many of the examples.  The name of a
  4749. + variable must be a sequence of letters, digits and underscores, but it
  4750. + may not begin with a digit.  Case is significant in variable names; `a'
  4751. + and `A' are distinct variables.
  4752. +    A variable name is a valid expression by itself; it represents the
  4753. + variable's current value.  Variables are given new values with
  4754. + "assignment operators" and "increment operators".  *Note Assignment
  4755. + Expressions: Assignment Ops.
  4756. +    A few variables have special built-in meanings, such as `FS', the
  4757. + field separator, and `NF', the number of fields in the current input
  4758. + record.  *Note Built-in Variables::, for a list of them.  These
  4759. + built-in variables can be used and assigned just like all other
  4760. + variables, but their values are also used or changed automatically by
  4761. + `awk'.  Each built-in variable's name is made entirely of upper case
  4762. + letters.
  4763. +    Variables in `awk' can be assigned either numeric or string values.
  4764. + By default, variables are initialized to the null string, which is
  4765. + effectively zero if converted to a number.  There is no need to
  4766. + "initialize" each variable explicitly in `awk', the way you would in C
  4767. + or most other traditional languages.
  4768. + * Menu:
  4769. + * Assignment Options::          Setting variables on the command line
  4770. +                                 and a summary of command line syntax.
  4771. +                                 This is an advanced method of input.
  4772. + 
  4773. + File: gawk.info,  Node: Assignment Options,  Prev: Variables,  Up: Variables
  4774. + Assigning Variables on the Command Line
  4775. + ---------------------------------------
  4776. +    You can set any `awk' variable by including a "variable assignment"
  4777. + among the arguments on the command line when you invoke `awk' (*note
  4778. + Invoking `awk': Command Line.).  Such an assignment has this form:
  4779. +      VARIABLE=TEXT
  4780. + With it, you can set a variable either at the beginning of the `awk'
  4781. + run or in between input files.
  4782. +    If you precede the assignment with the `-v' option, like this:
  4783. +      -v VARIABLE=TEXT
  4784. + then the variable is set at the very beginning, before even the `BEGIN'
  4785. + rules are run.  The `-v' option and its assignment must precede all the
  4786. + file name arguments, as well as the program text.
  4787. +    Otherwise, the variable assignment is performed at a time determined
  4788. + by its position among the input file arguments: after the processing of
  4789. + the preceding input file argument.  For example:
  4790. +      awk '{ print $n }' n=4 inventory-shipped n=2 BBS-list
  4791. + prints the value of field number `n' for all input records.  Before the
  4792. + first file is read, the command line sets the variable `n' equal to 4.
  4793. + This causes the fourth field to be printed in lines from the file
  4794. + `inventory-shipped'.  After the first file has finished, but before the
  4795. + second file is started, `n' is set to 2, so that the second field is
  4796. + printed in lines from `BBS-list'.
  4797. +    Command line arguments are made available for explicit examination by
  4798. + the `awk' program in an array named `ARGV' (*note Built-in
  4799. + Variables::.).
  4800. +    `awk' processes the values of command line assignments for escape
  4801. + sequences (*note Constant Expressions: Constants.).
  4802. + 
  4803. + File: gawk.info,  Node: Arithmetic Ops,  Next: Concatenation,  Prev: Variables,  Up: Expressions
  4804. + Arithmetic Operators
  4805. + ====================
  4806. +    The `awk' language uses the common arithmetic operators when
  4807. + evaluating expressions.  All of these arithmetic operators follow normal
  4808. + precedence rules, and work as you would expect them to.  This example
  4809. + divides field three by field four, adds field two, stores the result
  4810. + into field one, and prints the resulting altered input record:
  4811. +      awk '{ $1 = $2 + $3 / $4; print }' inventory-shipped
  4812. +    The arithmetic operators in `awk' are:
  4813. + `X + Y'
  4814. +      Addition.
  4815. + `X - Y'
  4816. +      Subtraction.
  4817. + `- X'
  4818. +      Negation.
  4819. + `+ X'
  4820. +      Unary plus.  No real effect on the expression.
  4821. + `X * Y'
  4822. +      Multiplication.
  4823. + `X / Y'
  4824. +      Division.  Since all numbers in `awk' are double-precision
  4825. +      floating point, the result is not rounded to an integer: `3 / 4'
  4826. +      has the value 0.75.
  4827. + `X % Y'
  4828. +      Remainder.  The quotient is rounded toward zero to an integer,
  4829. +      multiplied by Y and this result is subtracted from X.  This
  4830. +      operation is sometimes known as "trunc-mod."  The following
  4831. +      relation always holds:
  4832. +           b * int(a / b) + (a % b) == a
  4833. +      One possibly undesirable effect of this definition of remainder is
  4834. +      that `X % Y' is negative if X is negative.  Thus,
  4835. +           -17 % 8 = -1
  4836. +      In other `awk' implementations, the signedness of the remainder
  4837. +      may be machine dependent.
  4838. + `X ^ Y'
  4839. + `X ** Y'
  4840. +      Exponentiation: X raised to the Y power.  `2 ^ 3' has the value 8.
  4841. +      The character sequence `**' is equivalent to `^'.  (The POSIX
  4842. +      standard only specifies the use of `^' for exponentiation.)
  4843. + 
  4844. + File: gawk.info,  Node: Concatenation,  Next: Comparison Ops,  Prev: Arithmetic Ops,  Up: Expressions
  4845. + String Concatenation
  4846. + ====================
  4847. +    There is only one string operation: concatenation.  It does not have
  4848. + a specific operator to represent it.  Instead, concatenation is
  4849. + performed by writing expressions next to one another, with no operator.
  4850. + For example:
  4851. +      awk '{ print "Field number one: " $1 }' BBS-list
  4852. + produces, for the first record in `BBS-list':
  4853. +      Field number one: aardvark
  4854. +    Without the space in the string constant after the `:', the line
  4855. + would run together.  For example:
  4856. +      awk '{ print "Field number one:" $1 }' BBS-list
  4857. + produces, for the first record in `BBS-list':
  4858. +      Field number one:aardvark
  4859. +    Since string concatenation does not have an explicit operator, it is
  4860. + often necessary to insure that it happens where you want it to by
  4861. + enclosing the items to be concatenated in parentheses.  For example, the
  4862. + following code fragment does not concatenate `file' and `name' as you
  4863. + might expect:
  4864. +      file = "file"
  4865. +      name = "name"
  4866. +      print "something meaningful" > file name
  4867. + It is necessary to use the following:
  4868. +      print "something meaningful" > (file name)
  4869. +    We recommend you use parentheses around concatenation in all but the
  4870. + most common contexts (such as in the right-hand operand of `=').
  4871. + 
  4872. + File: gawk.info,  Node: Comparison Ops,  Next: Boolean Ops,  Prev: Concatenation,  Up: Expressions
  4873. + Comparison Expressions
  4874. + ======================
  4875. +    "Comparison expressions" compare strings or numbers for
  4876. + relationships such as equality.  They are written using "relational
  4877. + operators", which are a superset of those in C.  Here is a table of
  4878. + them:
  4879. + `X < Y'
  4880. +      True if X is less than Y.
  4881. + `X <= Y'
  4882. +      True if X is less than or equal to Y.
  4883. + `X > Y'
  4884. +      True if X is greater than Y.
  4885. + `X >= Y'
  4886. +      True if X is greater than or equal to Y.
  4887. + `X == Y'
  4888. +      True if X is equal to Y.
  4889. + `X != Y'
  4890. +      True if X is not equal to Y.
  4891. + `X ~ Y'
  4892. +      True if the string X matches the regexp denoted by Y.
  4893. + `X !~ Y'
  4894. +      True if the string X does not match the regexp denoted by Y.
  4895. + `SUBSCRIPT in ARRAY'
  4896. +      True if array ARRAY has an element with the subscript SUBSCRIPT.
  4897. +    Comparison expressions have the value 1 if true and 0 if false.
  4898. +    The rules `gawk' uses for performing comparisons are based on those
  4899. + in draft 11.2 of the POSIX standard.  The POSIX standard introduced the
  4900. + concept of a "numeric string", which is simply a string that looks like
  4901. + a number, for example, `" +2"'.
  4902. +    When performing a relational operation, `gawk' considers the type of
  4903. + an operand to be the type it received on its last *assignment*, rather
  4904. + than the type of its last *use* (*note Numeric and String Values:
  4905. + Values.).  This type is *unknown* when the operand is from an
  4906. + "external" source: field variables, command line arguments, array
  4907. + elements resulting from a `split' operation, and the value of an
  4908. + `ENVIRON' element.  In this case only, if the operand is a numeric
  4909. + string, then it is considered to be of both string type and numeric
  4910. + type.  If at least one operand of a comparison is of string type only,
  4911. + then a string comparison is performed.  Any numeric operand will be
  4912. + converted to a string using the value of `CONVFMT' (*note Conversion of
  4913. + Strings and Numbers: Conversion.).  If one operand of a comparison is
  4914. + numeric, and the other operand is either numeric or both numeric and
  4915. + string, then `gawk' does a numeric comparison.  If both operands have
  4916. + both types, then the comparison is numeric.  Strings are compared by
  4917. + comparing the first character of each, then the second character of
  4918. + each, and so on.  Thus `"10"' is less than `"9"'.  If there are two
  4919. + strings where one is a prefix of the other, the shorter string is less
  4920. + than the longer one.  Thus `"abc"' is less than `"abcd"'.
  4921. +    Here are some sample expressions, how `gawk' compares them, and what
  4922. + the result of the comparison is.
  4923. + `1.5 <= 2.0'
  4924. +      numeric comparison (true)
  4925. + `"abc" >= "xyz"'
  4926. +      string comparison (false)
  4927. + `1.5 != " +2"'
  4928. +      string comparison (true)
  4929. + `"1e2" < "3"'
  4930. +      string comparison (true)
  4931. + `a = 2; b = "2"'
  4932. + `a == b'
  4933. +      string comparison (true)
  4934. +      echo 1e2 3 | awk '{ print ($1 < $2) ? "true" : "false" }'
  4935. + prints `false' since both `$1' and `$2' are numeric strings and thus
  4936. + have both string and numeric types, thus dictating a numeric comparison.
  4937. +    The purpose of the comparison rules and the use of numeric strings is
  4938. + to attempt to produce the behavior that is "least surprising," while
  4939. + still "doing the right thing."
  4940. +    String comparisons and regular expression comparisons are very
  4941. + different.  For example,
  4942. +      $1 == "foo"
  4943. + has the value of 1, or is true, if the first field of the current input
  4944. + record is precisely `foo'.  By contrast,
  4945. +      $1 ~ /foo/
  4946. + has the value 1 if the first field contains `foo', such as `foobar'.
  4947. +    The right hand operand of the `~' and `!~' operators may be either a
  4948. + constant regexp (`/.../'), or it may be an ordinary expression, in
  4949. + which case the value of the expression as a string is a dynamic regexp
  4950. + (*note How to Use Regular Expressions: Regexp Usage.).
  4951. +    In very recent implementations of `awk', a constant regular
  4952. + expression in slashes by itself is also an expression.  The regexp
  4953. + `/REGEXP/' is an abbreviation for this comparison expression:
  4954. +      $0 ~ /REGEXP/
  4955. +    In some contexts it may be necessary to write parentheses around the
  4956. + regexp to avoid confusing the `gawk' parser.  For example, `(/x/ - /y/)
  4957. + > threshold' is not allowed, but `((/x/) - (/y/)) > threshold' parses
  4958. + properly.
  4959. +    One special place where `/foo/' is *not* an abbreviation for `$0 ~
  4960. + /foo/' is when it is the right-hand operand of `~' or `!~'! *Note
  4961. + Constant Expressions: Constants, where this is discussed in more detail.
  4962. + 
  4963. + File: gawk.info,  Node: Boolean Ops,  Next: Assignment Ops,  Prev: Comparison Ops,  Up: Expressions
  4964. + Boolean Expressions
  4965. + ===================
  4966. +    A "boolean expression" is a combination of comparison expressions or
  4967. + matching expressions, using the boolean operators "or" (`||'), "and"
  4968. + (`&&'), and "not" (`!'), along with parentheses to control nesting.
  4969. + The truth of the boolean expression is computed by combining the truth
  4970. + values of the component expressions.
  4971. +    Boolean expressions can be used wherever comparison and matching
  4972. + expressions can be used.  They can be used in `if', `while' `do' and
  4973. + `for' statements.  They have numeric values (1 if true, 0 if false),
  4974. + which come into play if the result of the boolean expression is stored
  4975. + in a variable, or used in arithmetic.
  4976. +    In addition, every boolean expression is also a valid boolean
  4977. + pattern, so you can use it as a pattern to control the execution of
  4978. + rules.
  4979. +    Here are descriptions of the three boolean operators, with an
  4980. + example of each.  It may be instructive to compare these examples with
  4981. + the analogous examples of boolean patterns (*note Boolean Operators and
  4982. + Patterns: Boolean Patterns.), which use the same boolean operators in
  4983. + patterns instead of expressions.
  4984. + `BOOLEAN1 && BOOLEAN2'
  4985. +      True if both BOOLEAN1 and BOOLEAN2 are true.  For example, the
  4986. +      following statement prints the current input record if it contains
  4987. +      both `2400' and `foo'.
  4988. +           if ($0 ~ /2400/ && $0 ~ /foo/) print
  4989. +      The subexpression BOOLEAN2 is evaluated only if BOOLEAN1 is true.
  4990. +      This can make a difference when BOOLEAN2 contains expressions that
  4991. +      have side effects: in the case of `$0 ~ /foo/ && ($2 == bar++)',
  4992. +      the variable `bar' is not incremented if there is no `foo' in the
  4993. +      record.
  4994. + `BOOLEAN1 || BOOLEAN2'
  4995. +      True if at least one of BOOLEAN1 or BOOLEAN2 is true.  For
  4996. +      example, the following command prints all records in the input
  4997. +      file `BBS-list' that contain *either* `2400' or `foo', or both.
  4998. +           awk '{ if ($0 ~ /2400/ || $0 ~ /foo/) print }' BBS-list
  4999. +      The subexpression BOOLEAN2 is evaluated only if BOOLEAN1 is false.
  5000. +      This can make a difference when BOOLEAN2 contains expressions
  5001. +      that have side effects.
  5002. + `!BOOLEAN'
  5003. +      True if BOOLEAN is false.  For example, the following program
  5004. +      prints all records in the input file `BBS-list' that do *not*
  5005. +      contain the string `foo'.
  5006. +           awk '{ if (! ($0 ~ /foo/)) print }' BBS-list
  5007. + 
  5008. + File: gawk.info,  Node: Assignment Ops,  Next: Increment Ops,  Prev: Boolean Ops,  Up: Expressions
  5009. + Assignment Expressions
  5010. + ======================
  5011. +    An "assignment" is an expression that stores a new value into a
  5012. + variable.  For example, let's assign the value 1 to the variable `z':
  5013. +      z = 1
  5014. +    After this expression is executed, the variable `z' has the value 1.
  5015. + Whatever old value `z' had before the assignment is forgotten.
  5016. +    Assignments can store string values also.  For example, this would
  5017. + store the value `"this food is good"' in the variable `message':
  5018. +      thing = "food"
  5019. +      predicate = "good"
  5020. +      message = "this " thing " is " predicate
  5021. + (This also illustrates concatenation of strings.)
  5022. +    The `=' sign is called an "assignment operator".  It is the simplest
  5023. + assignment operator because the value of the right-hand operand is
  5024. + stored unchanged.
  5025. +    Most operators (addition, concatenation, and so on) have no effect
  5026. + except to compute a value.  If you ignore the value, you might as well
  5027. + not use the operator.  An assignment operator is different; it does
  5028. + produce a value, but even if you ignore the value, the assignment still
  5029. + makes itself felt through the alteration of the variable.  We call this
  5030. + a "side effect".
  5031. +    The left-hand operand of an assignment need not be a variable (*note
  5032. + Variables::.); it can also be a field (*note Changing the Contents of a
  5033. + Field: Changing Fields.) or an array element (*note Arrays in `awk':
  5034. + Arrays.).  These are all called "lvalues", which means they can appear
  5035. + on the left-hand side of an assignment operator.  The right-hand
  5036. + operand may be any expression; it produces the new value which the
  5037. + assignment stores in the specified variable, field or array element.
  5038. +    It is important to note that variables do *not* have permanent types.
  5039. + The type of a variable is simply the type of whatever value it happens
  5040. + to hold at the moment.  In the following program fragment, the variable
  5041. + `foo' has a numeric value at first, and a string value later on:
  5042. +      foo = 1
  5043. +      print foo
  5044. +      foo = "bar"
  5045. +      print foo
  5046. + When the second assignment gives `foo' a string value, the fact that it
  5047. + previously had a numeric value is forgotten.
  5048. +    An assignment is an expression, so it has a value: the same value
  5049. + that is assigned.  Thus, `z = 1' as an expression has the value 1.  One
  5050. + consequence of this is that you can write multiple assignments together:
  5051. +      x = y = z = 0
  5052. + stores the value 0 in all three variables.  It does this because the
  5053. + value of `z = 0', which is 0, is stored into `y', and then the value of
  5054. + `y = z = 0', which is 0, is stored into `x'.
  5055. +    You can use an assignment anywhere an expression is called for.  For
  5056. + example, it is valid to write `x != (y = 1)' to set `y' to 1 and then
  5057. + test whether `x' equals 1.  But this style tends to make programs hard
  5058. + to read; except in a one-shot program, you should rewrite it to get rid
  5059. + of such nesting of assignments.  This is never very hard.
  5060. +    Aside from `=', there are several other assignment operators that do
  5061. + arithmetic with the old value of the variable.  For example, the
  5062. + operator `+=' computes a new value by adding the right-hand value to
  5063. + the old value of the variable.  Thus, the following assignment adds 5
  5064. + to the value of `foo':
  5065. +      foo += 5
  5066. + This is precisely equivalent to the following:
  5067. +      foo = foo + 5
  5068. + Use whichever one makes the meaning of your program clearer.
  5069. +    Here is a table of the arithmetic assignment operators.  In each
  5070. + case, the right-hand operand is an expression whose value is converted
  5071. + to a number.
  5072. + `LVALUE += INCREMENT'
  5073. +      Adds INCREMENT to the value of LVALUE to make the new value of
  5074. +      LVALUE.
  5075. + `LVALUE -= DECREMENT'
  5076. +      Subtracts DECREMENT from the value of LVALUE.
  5077. + `LVALUE *= COEFFICIENT'
  5078. +      Multiplies the value of LVALUE by COEFFICIENT.
  5079. + `LVALUE /= QUOTIENT'
  5080. +      Divides the value of LVALUE by QUOTIENT.
  5081. + `LVALUE %= MODULUS'
  5082. +      Sets LVALUE to its remainder by MODULUS.
  5083. + `LVALUE ^= POWER'
  5084. + `LVALUE **= POWER'
  5085. +      Raises LVALUE to the power POWER.  (Only the `^=' operator is
  5086. +      specified by POSIX.)
  5087. + 
  5088. + File: gawk.info,  Node: Increment Ops,  Next: Conversion,  Prev: Assignment Ops,  Up: Expressions
  5089. + Increment Operators
  5090. + ===================
  5091. +    "Increment operators" increase or decrease the value of a variable
  5092. + by 1.  You could do the same thing with an assignment operator, so the
  5093. + increment operators add no power to the `awk' language; but they are
  5094. + convenient abbreviations for something very common.
  5095. +    The operator to add 1 is written `++'.  It can be used to increment
  5096. + a variable either before or after taking its value.
  5097. +    To pre-increment a variable V, write `++V'.  This adds 1 to the
  5098. + value of V and that new value is also the value of this expression.
  5099. + The assignment expression `V += 1' is completely equivalent.
  5100. +    Writing the `++' after the variable specifies post-increment.  This
  5101. + increments the variable value just the same; the difference is that the
  5102. + value of the increment expression itself is the variable's *old* value.
  5103. + Thus, if `foo' has the value 4, then the expression `foo++' has the
  5104. + value 4, but it changes the value of `foo' to 5.
  5105. +    The post-increment `foo++' is nearly equivalent to writing `(foo +=
  5106. + 1) - 1'.  It is not perfectly equivalent because all numbers in `awk'
  5107. + are floating point: in floating point, `foo + 1 - 1' does not
  5108. + necessarily equal `foo'.  But the difference is minute as long as you
  5109. + stick to numbers that are fairly small (less than a trillion).
  5110. +    Any lvalue can be incremented.  Fields and array elements are
  5111. + incremented just like variables.  (Use `$(i++)' when you wish to do a
  5112. + field reference and a variable increment at the same time.  The
  5113. + parentheses are necessary because of the precedence of the field
  5114. + reference operator, `$'.)
  5115. +    The decrement operator `--' works just like `++' except that it
  5116. + subtracts 1 instead of adding.  Like `++', it can be used before the
  5117. + lvalue to pre-decrement or after it to post-decrement.
  5118. +    Here is a summary of increment and decrement expressions.
  5119. + `++LVALUE'
  5120. +      This expression increments LVALUE and the new value becomes the
  5121. +      value of this expression.
  5122. + `LVALUE++'
  5123. +      This expression causes the contents of LVALUE to be incremented.
  5124. +      The value of the expression is the *old* value of LVALUE.
  5125. + `--LVALUE'
  5126. +      Like `++LVALUE', but instead of adding, it subtracts.  It
  5127. +      decrements LVALUE and delivers the value that results.
  5128. + `LVALUE--'
  5129. +      Like `LVALUE++', but instead of adding, it subtracts.  It
  5130. +      decrements LVALUE.  The value of the expression is the *old* value
  5131. +      of LVALUE.
  5132. + 
  5133. + File: gawk.info,  Node: Conversion,  Next: Values,  Prev: Increment Ops,  Up: Expressions
  5134. + Conversion of Strings and Numbers
  5135. + =================================
  5136. +    Strings are converted to numbers, and numbers to strings, if the
  5137. + context of the `awk' program demands it.  For example, if the value of
  5138. + either `foo' or `bar' in the expression `foo + bar' happens to be a
  5139. + string, it is converted to a number before the addition is performed.
  5140. + If numeric values appear in string concatenation, they are converted to
  5141. + strings.  Consider this:
  5142. +      two = 2; three = 3
  5143. +      print (two three) + 4
  5144. + This eventually prints the (numeric) value 27.  The numeric values of
  5145. + the variables `two' and `three' are converted to strings and
  5146. + concatenated together, and the resulting string is converted back to the
  5147. + number 23, to which 4 is then added.
  5148. +    If, for some reason, you need to force a number to be converted to a
  5149. + string, concatenate the null string with that number.  To force a string
  5150. + to be converted to a number, add zero to that string.
  5151. +    A string is converted to a number by interpreting a numeric prefix
  5152. + of the string as numerals: `"2.5"' converts to 2.5, `"1e3"' converts to
  5153. + 1000, and `"25fix"' has a numeric value of 25.  Strings that can't be
  5154. + interpreted as valid numbers are converted to zero.
  5155. +    The exact manner in which numbers are converted into strings is
  5156. + controlled by the `awk' built-in variable `CONVFMT' (*note Built-in
  5157. + Variables::.).  Numbers are converted using a special version of the
  5158. + `sprintf' function (*note Built-in Functions: Built-in.) with `CONVFMT'
  5159. + as the format specifier.
  5160. +    `CONVFMT''s default value is `"%.6g"', which prints a value with at
  5161. + least six significant digits.  For some applications you will want to
  5162. + change it to specify more precision.  Double precision on most modern
  5163. + machines gives you 16 or 17 decimal digits of precision.
  5164. +    Strange results can happen if you set `CONVFMT' to a string that
  5165. + doesn't tell `sprintf' how to format floating point numbers in a useful
  5166. + way.  For example, if you forget the `%' in the format, all numbers
  5167. + will be converted to the same constant string.
  5168. +    As a special case, if a number is an integer, then the result of
  5169. + converting it to a string is *always* an integer, no matter what the
  5170. + value of `CONVFMT' may be.  Given the following code fragment:
  5171. +      CONVFMT = "%2.2f"
  5172. +      a = 12
  5173. +      b = a ""
  5174. + `b' has the value `"12"', not `"12.00"'.
  5175. +    Prior to the POSIX standard, `awk' specified that the value of
  5176. + `OFMT' was used for converting numbers to strings.  `OFMT' specifies
  5177. + the output format to use when printing numbers with `print'.  `CONVFMT'
  5178. + was introduced in order to separate the semantics of conversions from
  5179. + the semantics of printing.  Both `CONVFMT' and `OFMT' have the same
  5180. + default value: `"%.6g"'.  In the vast majority of cases, old `awk'
  5181. + programs will not change their behavior.  However, this use of `OFMT'
  5182. + is something to keep in mind if you must port your program to other
  5183. + implementations of `awk'; we recommend that instead of changing your
  5184. + programs, you just port `gawk' itself!
  5185. + 
  5186. + File: gawk.info,  Node: Values,  Next: Conditional Exp,  Prev: Conversion,  Up: Expressions
  5187. + Numeric and String Values
  5188. + =========================
  5189. +    Through most of this manual, we present `awk' values (such as
  5190. + constants, fields, or variables) as *either* numbers *or* strings.
  5191. + This is a convenient way to think about them, since typically they are
  5192. + used in only one way, or the other.
  5193. +    In truth though, `awk' values can be *both* string and numeric, at
  5194. + the same time.  Internally, `awk' represents values with a string, a
  5195. + (floating point) number, and an indication that one, the other, or both
  5196. + representations of the value are valid.
  5197. +    Keeping track of both kinds of values is important for execution
  5198. + efficiency:  a variable can acquire a string value the first time it is
  5199. + used as a string, and then that string value can be used until the
  5200. + variable is assigned a new value.  Thus, if a variable with only a
  5201. + numeric value is used in several concatenations in a row, it only has
  5202. + to be given a string representation once.  The numeric value remains
  5203. + valid, so that no conversion back to a number is necessary if the
  5204. + variable is later used in an arithmetic expression.
  5205. +    Tracking both kinds of values is also important for precise numerical
  5206. + calculations.  Consider the following:
  5207. +      a = 123.321
  5208. +      CONVFMT = "%3.1f"
  5209. +      b = a " is a number"
  5210. +      c = a + 1.654
  5211. + The variable `a' receives a string value in the concatenation and
  5212. + assignment to `b'.  The string value of `a' is `"123.3"'.  If the
  5213. + numeric value was lost when it was converted to a string, then the
  5214. + numeric use of `a' in the last statement would lose information.  `c'
  5215. + would be assigned the value 124.954 instead of 124.975.  Such errors
  5216. + accumulate rapidly, and very adversely affect numeric computations.
  5217. +    Once a numeric value acquires a corresponding string value, it stays
  5218. + valid until a new assignment is made.  If `CONVFMT' (*note Conversion
  5219. + of Strings and Numbers: Conversion.) changes in the meantime, the old
  5220. + string value will still be used.  For example:
  5221. +      BEGIN {
  5222. +          CONVFMT = "%2.2f"
  5223. +          a = 123.456
  5224. +          b = a ""                # force `a' to have string value too
  5225. +          printf "a = %s\n", a
  5226. +          CONVFMT = "%.6g"
  5227. +          printf "a = %s\n", a
  5228. +          a += 0                  # make `a' numeric only again
  5229. +          printf "a = %s\n", a    # use `a' as string
  5230. +      }
  5231. + This program prints `a = 123.46' twice, and then prints `a = 123.456'.
  5232. +    *Note Conversion of Strings and Numbers: Conversion, for the rules
  5233. + that specify how string values are made from numeric values.
  5234. + 
  5235. + File: gawk.info,  Node: Conditional Exp,  Next: Function Calls,  Prev: Values,  Up: Expressions
  5236. + Conditional Expressions
  5237. + =======================
  5238. +    A "conditional expression" is a special kind of expression with
  5239. + three operands.  It allows you to use one expression's value to select
  5240. + one of two other expressions.
  5241. +    The conditional expression looks the same as in the C language:
  5242. +      SELECTOR ? IF-TRUE-EXP : IF-FALSE-EXP
  5243. + There are three subexpressions.  The first, SELECTOR, is always
  5244. + computed first.  If it is "true" (not zero and not null) then
  5245. + IF-TRUE-EXP is computed next and its value becomes the value of the
  5246. + whole expression.  Otherwise, IF-FALSE-EXP is computed next and its
  5247. + value becomes the value of the whole expression.
  5248. +    For example, this expression produces the absolute value of `x':
  5249. +      x > 0 ? x : -x
  5250. +    Each time the conditional expression is computed, exactly one of
  5251. + IF-TRUE-EXP and IF-FALSE-EXP is computed; the other is ignored.  This
  5252. + is important when the expressions contain side effects.  For example,
  5253. + this conditional expression examines element `i' of either array `a' or
  5254. + array `b', and increments `i'.
  5255. +      x == y ? a[i++] : b[i++]
  5256. + This is guaranteed to increment `i' exactly once, because each time one
  5257. + or the other of the two increment expressions is executed, and the
  5258. + other is not.
  5259. + 
  5260. + File: gawk.info,  Node: Function Calls,  Next: Precedence,  Prev: Conditional Exp,  Up: Expressions
  5261. + Function Calls
  5262. + ==============
  5263. +    A "function" is a name for a particular calculation.  Because it has
  5264. + a name, you can ask for it by name at any point in the program.  For
  5265. + example, the function `sqrt' computes the square root of a number.
  5266. +    A fixed set of functions are "built-in", which means they are
  5267. + available in every `awk' program.  The `sqrt' function is one of these.
  5268. + *Note Built-in Functions: Built-in, for a list of built-in functions
  5269. + and their descriptions.  In addition, you can define your own functions
  5270. + in the program for use elsewhere in the same program.  *Note
  5271. + User-defined Functions: User-defined, for how to do this.
  5272. +    The way to use a function is with a "function call" expression,
  5273. + which consists of the function name followed by a list of "arguments"
  5274. + in parentheses.  The arguments are expressions which give the raw
  5275. + materials for the calculation that the function will do.  When there is
  5276. + more than one argument, they are separated by commas.  If there are no
  5277. + arguments, write just `()' after the function name.  Here are some
  5278. + examples:
  5279. +      sqrt(x^2 + y^2)      # One argument
  5280. +      atan2(y, x)          # Two arguments
  5281. +      rand()               # No arguments
  5282. +    *Do not put any space between the function name and the
  5283. + open-parenthesis!*  A user-defined function name looks just like the
  5284. + name of a variable, and space would make the expression look like
  5285. + concatenation of a variable with an expression inside parentheses.
  5286. + Space before the parenthesis is harmless with built-in functions, but
  5287. + it is best not to get into the habit of using space to avoid mistakes
  5288. + with user-defined functions.
  5289. +    Each function expects a particular number of arguments.  For
  5290. + example, the `sqrt' function must be called with a single argument, the
  5291. + number to take the square root of:
  5292. +      sqrt(ARGUMENT)
  5293. +    Some of the built-in functions allow you to omit the final argument.
  5294. + If you do so, they use a reasonable default.  *Note Built-in Functions:
  5295. + Built-in, for full details.  If arguments are omitted in calls to
  5296. + user-defined functions, then those arguments are treated as local
  5297. + variables, initialized to the null string (*note User-defined
  5298. + Functions: User-defined.).
  5299. +    Like every other expression, the function call has a value, which is
  5300. + computed by the function based on the arguments you give it.  In this
  5301. + example, the value of `sqrt(ARGUMENT)' is the square root of the
  5302. + argument.  A function can also have side effects, such as assigning the
  5303. + values of certain variables or doing I/O.
  5304. +    Here is a command to read numbers, one number per line, and print the
  5305. + square root of each one:
  5306. +      awk '{ print "The square root of", $1, "is", sqrt($1) }'
  5307. + 
  5308. + File: gawk.info,  Node: Precedence,  Prev: Function Calls,  Up: Expressions
  5309. + Operator Precedence (How Operators Nest)
  5310. + ========================================
  5311. +    "Operator precedence" determines how operators are grouped, when
  5312. + different operators appear close by in one expression.  For example,
  5313. + `*' has higher precedence than `+'; thus, `a + b * c' means to multiply
  5314. + `b' and `c', and then add `a' to the product (i.e., `a + (b * c)').
  5315. +    You can overrule the precedence of the operators by using
  5316. + parentheses.  You can think of the precedence rules as saying where the
  5317. + parentheses are assumed if you do not write parentheses yourself.  In
  5318. + fact, it is wise to always use parentheses whenever you have an unusual
  5319. + combination of operators, because other people who read the program may
  5320. + not remember what the precedence is in this case.  You might forget,
  5321. + too; then you could make a mistake.  Explicit parentheses will help
  5322. + prevent any such mistake.
  5323. +    When operators of equal precedence are used together, the leftmost
  5324. + operator groups first, except for the assignment, conditional and
  5325. + exponentiation operators, which group in the opposite order.  Thus, `a
  5326. + - b + c' groups as `(a - b) + c'; `a = b = c' groups as `a = (b = c)'.
  5327. +    The precedence of prefix unary operators does not matter as long as
  5328. + only unary operators are involved, because there is only one way to
  5329. + parse them--innermost first.  Thus, `$++i' means `$(++i)' and `++$x'
  5330. + means `++($x)'.  However, when another operator follows the operand,
  5331. + then the precedence of the unary operators can matter.  Thus, `$x^2'
  5332. + means `($x)^2', but `-x^2' means `-(x^2)', because `-' has lower
  5333. + precedence than `^' while `$' has higher precedence.
  5334. +    Here is a table of the operators of `awk', in order of increasing
  5335. + precedence:
  5336. + assignment
  5337. +      `=', `+=', `-=', `*=', `/=', `%=', `^=', `**='.  These operators
  5338. +      group right-to-left.  (The `**=' operator is not specified by
  5339. +      POSIX.)
  5340. + conditional
  5341. +      `?:'.  This operator groups right-to-left.
  5342. + logical "or".
  5343. +      `||'.
  5344. + logical "and".
  5345. +      `&&'.
  5346. + array membership
  5347. +      `in'.
  5348. + matching
  5349. +      `~', `!~'.
  5350. + relational, and redirection
  5351. +      The relational operators and the redirections have the same
  5352. +      precedence level.  Characters such as `>' serve both as
  5353. +      relationals and as redirections; the context distinguishes between
  5354. +      the two meanings.
  5355. +      The relational operators are `<', `<=', `==', `!=', `>=' and `>'.
  5356. +      The I/O redirection operators are `<', `>', `>>' and `|'.
  5357. +      Note that I/O redirection operators in `print' and `printf'
  5358. +      statements belong to the statement level, not to expressions.  The
  5359. +      redirection does not produce an expression which could be the
  5360. +      operand of another operator.  As a result, it does not make sense
  5361. +      to use a redirection operator near another operator of lower
  5362. +      precedence, without parentheses.  Such combinations, for example
  5363. +      `print foo > a ? b : c', result in syntax errors.
  5364. + concatenation
  5365. +      No special token is used to indicate concatenation.  The operands
  5366. +      are simply written side by side.
  5367. + add, subtract
  5368. +      `+', `-'.
  5369. + multiply, divide, mod
  5370. +      `*', `/', `%'.
  5371. + unary plus, minus, "not"
  5372. +      `+', `-', `!'.
  5373. + exponentiation
  5374. +      `^', `**'.  These operators group right-to-left.  (The `**'
  5375. +      operator is not specified by POSIX.)
  5376. + increment, decrement
  5377. +      `++', `--'.
  5378. + field
  5379. +      `$'.
  5380. + 
  5381. + File: gawk.info,  Node: Statements,  Next: Arrays,  Prev: Expressions,  Up: Top
  5382. + Control Statements in Actions
  5383. + *****************************
  5384. +    "Control statements" such as `if', `while', and so on control the
  5385. + flow of execution in `awk' programs.  Most of the control statements in
  5386. + `awk' are patterned on similar statements in C.
  5387. +    All the control statements start with special keywords such as `if'
  5388. + and `while', to distinguish them from simple expressions.
  5389. +    Many control statements contain other statements; for example, the
  5390. + `if' statement contains another statement which may or may not be
  5391. + executed.  The contained statement is called the "body".  If you want
  5392. + to include more than one statement in the body, group them into a
  5393. + single compound statement with curly braces, separating them with
  5394. + newlines or semicolons.
  5395. + * Menu:
  5396. + * If Statement::                Conditionally execute
  5397. +                                 some `awk' statements.
  5398. + * While Statement::             Loop until some condition is satisfied.
  5399. + * Do Statement::                Do specified action while looping until some
  5400. +                                 condition is satisfied.
  5401. + * For Statement::               Another looping statement, that provides
  5402. +                                 initialization and increment clauses.
  5403. + * Break Statement::             Immediately exit the innermost enclosing loop.
  5404. + * Continue Statement::          Skip to the end of the innermost
  5405. +                                 enclosing loop.
  5406. + * Next Statement::              Stop processing the current input record.
  5407. + * Next File Statement::         Stop processing the current file.
  5408. + * Exit Statement::              Stop execution of `awk'.
  5409. + 
  5410. + File: gawk.info,  Node: If Statement,  Next: While Statement,  Prev: Statements,  Up: Statements
  5411. + The `if' Statement
  5412. + ==================
  5413. +    The `if'-`else' statement is `awk''s decision-making statement.  It
  5414. + looks like this:
  5415. +      if (CONDITION) THEN-BODY [else ELSE-BODY]
  5416. + CONDITION is an expression that controls what the rest of the statement
  5417. + will do.  If CONDITION is true, THEN-BODY is executed; otherwise,
  5418. + ELSE-BODY is executed (assuming that the `else' clause is present).
  5419. + The `else' part of the statement is optional.  The condition is
  5420. + considered false if its value is zero or the null string, and true
  5421. + otherwise.
  5422. +    Here is an example:
  5423. +      if (x % 2 == 0)
  5424. +          print "x is even"
  5425. +      else
  5426. +          print "x is odd"
  5427. +    In this example, if the expression `x % 2 == 0' is true (that is,
  5428. + the value of `x' is divisible by 2), then the first `print' statement
  5429. + is executed, otherwise the second `print' statement is performed.
  5430. +    If the `else' appears on the same line as THEN-BODY, and THEN-BODY
  5431. + is not a compound statement (i.e., not surrounded by curly braces),
  5432. + then a semicolon must separate THEN-BODY from `else'.  To illustrate
  5433. + this, let's rewrite the previous example:
  5434. +      awk '{ if (x % 2 == 0) print "x is even"; else
  5435. +              print "x is odd" }'
  5436. + If you forget the `;', `awk' won't be able to parse the statement, and
  5437. + you will get a syntax error.
  5438. +    We would not actually write this example this way, because a human
  5439. + reader might fail to see the `else' if it were not the first thing on
  5440. + its line.
  5441. + 
  5442. + File: gawk.info,  Node: While Statement,  Next: Do Statement,  Prev: If Statement,  Up: Statements
  5443. + The `while' Statement
  5444. + =====================
  5445. +    In programming, a "loop" means a part of a program that is (or at
  5446. + least can be) executed two or more times in succession.
  5447. +    The `while' statement is the simplest looping statement in `awk'.
  5448. + It repeatedly executes a statement as long as a condition is true.  It
  5449. + looks like this:
  5450. +      while (CONDITION)
  5451. +        BODY
  5452. + Here BODY is a statement that we call the "body" of the loop, and
  5453. + CONDITION is an expression that controls how long the loop keeps
  5454. + running.
  5455. +    The first thing the `while' statement does is test CONDITION.  If
  5456. + CONDITION is true, it executes the statement BODY.  (CONDITION is true
  5457. + when the value is not zero and not a null string.)  After BODY has been
  5458. + executed, CONDITION is tested again, and if it is still true, BODY is
  5459. + executed again.  This process repeats until CONDITION is no longer
  5460. + true.  If CONDITION is initially false, the body of the loop is never
  5461. + executed.
  5462. +    This example prints the first three fields of each record, one per
  5463. + line.
  5464. +      awk '{ i = 1
  5465. +             while (i <= 3) {
  5466. +                 print $i
  5467. +                 i++
  5468. +             }
  5469. +      }'
  5470. + Here the body of the loop is a compound statement enclosed in braces,
  5471. + containing two statements.
  5472. +    The loop works like this: first, the value of `i' is set to 1.
  5473. + Then, the `while' tests whether `i' is less than or equal to three.
  5474. + This is the case when `i' equals one, so the `i'-th field is printed.
  5475. + Then the `i++' increments the value of `i' and the loop repeats.  The
  5476. + loop terminates when `i' reaches 4.
  5477. +    As you can see, a newline is not required between the condition and
  5478. + the body; but using one makes the program clearer unless the body is a
  5479. + compound statement or is very simple.  The newline after the open-brace
  5480. + that begins the compound statement is not required either, but the
  5481. + program would be hard to read without it.
  5482. + 
  5483. + File: gawk.info,  Node: Do Statement,  Next: For Statement,  Prev: While Statement,  Up: Statements
  5484. + The `do'-`while' Statement
  5485. + ==========================
  5486. +    The `do' loop is a variation of the `while' looping statement.  The
  5487. + `do' loop executes the BODY once, then repeats BODY as long as
  5488. + CONDITION is true.  It looks like this:
  5489. +      do
  5490. +        BODY
  5491. +      while (CONDITION)
  5492. +    Even if CONDITION is false at the start, BODY is executed at least
  5493. + once (and only once, unless executing BODY makes CONDITION true).
  5494. + Contrast this with the corresponding `while' statement:
  5495. +      while (CONDITION)
  5496. +        BODY
  5497. + This statement does not execute BODY even once if CONDITION is false to
  5498. + begin with.
  5499. +    Here is an example of a `do' statement:
  5500. +      awk '{ i = 1
  5501. +             do {
  5502. +                print $0
  5503. +                i++
  5504. +             } while (i <= 10)
  5505. +      }'
  5506. + prints each input record ten times.  It isn't a very realistic example,
  5507. + since in this case an ordinary `while' would do just as well.  But this
  5508. + reflects actual experience; there is only occasionally a real use for a
  5509. + `do' statement.
  5510. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-5 gawk-2.15.5/gawk.info-5
  5511. *** /src/baseline/gawk-2.15.5/gawk.info-5    Thu Jan  1 00:00:00 1970
  5512. --- gawk-2.15.5/gawk.info-5    Sun Jun 12 22:28:52 1994
  5513. ***************
  5514. *** 0 ****
  5515. --- 1,1256 ----
  5516. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  5517. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  5518. +    This file documents `awk', a program that you can use to select
  5519. + particular records in a file and perform operations upon them.
  5520. +    This is Edition 0.15 of `The GAWK Manual',
  5521. + for the 2.15 version of the GNU implementation
  5522. + of AWK.
  5523. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  5524. +    Permission is granted to make and distribute verbatim copies of this
  5525. + manual provided the copyright notice and this permission notice are
  5526. + preserved on all copies.
  5527. +    Permission is granted to copy and distribute modified versions of
  5528. + this manual under the conditions for verbatim copying, provided that
  5529. + the entire resulting derived work is distributed under the terms of a
  5530. + permission notice identical to this one.
  5531. +    Permission is granted to copy and distribute translations of this
  5532. + manual into another language, under the above conditions for modified
  5533. + versions, except that this permission notice may be stated in a
  5534. + translation approved by the Foundation.
  5535. + 
  5536. + File: gawk.info,  Node: For Statement,  Next: Break Statement,  Prev: Do Statement,  Up: Statements
  5537. + The `for' Statement
  5538. + ===================
  5539. +    The `for' statement makes it more convenient to count iterations of a
  5540. + loop.  The general form of the `for' statement looks like this:
  5541. +      for (INITIALIZATION; CONDITION; INCREMENT)
  5542. +        BODY
  5543. + This statement starts by executing INITIALIZATION.  Then, as long as
  5544. + CONDITION is true, it repeatedly executes BODY and then INCREMENT.
  5545. + Typically INITIALIZATION sets a variable to either zero or one,
  5546. + INCREMENT adds 1 to it, and CONDITION compares it against the desired
  5547. + number of iterations.
  5548. +    Here is an example of a `for' statement:
  5549. +      awk '{ for (i = 1; i <= 3; i++)
  5550. +                print $i
  5551. +      }'
  5552. + This prints the first three fields of each input record, one field per
  5553. + line.
  5554. +    In the `for' statement, BODY stands for any statement, but
  5555. + INITIALIZATION, CONDITION and INCREMENT are just expressions.  You
  5556. + cannot set more than one variable in the INITIALIZATION part unless you
  5557. + use a multiple assignment statement such as `x = y = 0', which is
  5558. + possible only if all the initial values are equal.  (But you can
  5559. + initialize additional variables by writing their assignments as
  5560. + separate statements preceding the `for' loop.)
  5561. +    The same is true of the INCREMENT part; to increment additional
  5562. + variables, you must write separate statements at the end of the loop.
  5563. + The C compound expression, using C's comma operator, would be useful in
  5564. + this context, but it is not supported in `awk'.
  5565. +    Most often, INCREMENT is an increment expression, as in the example
  5566. + above.  But this is not required; it can be any expression whatever.
  5567. + For example, this statement prints all the powers of 2 between 1 and
  5568. + 100:
  5569. +      for (i = 1; i <= 100; i *= 2)
  5570. +        print i
  5571. +    Any of the three expressions in the parentheses following the `for'
  5572. + may be omitted if there is nothing to be done there.  Thus,
  5573. + `for (;x > 0;)' is equivalent to `while (x > 0)'.  If the CONDITION is
  5574. + omitted, it is treated as TRUE, effectively yielding an "infinite loop"
  5575. + (i.e., a loop that will never terminate).
  5576. +    In most cases, a `for' loop is an abbreviation for a `while' loop,
  5577. + as shown here:
  5578. +      INITIALIZATION
  5579. +      while (CONDITION) {
  5580. +        BODY
  5581. +        INCREMENT
  5582. +      }
  5583. + The only exception is when the `continue' statement (*note The
  5584. + `continue' Statement: Continue Statement.) is used inside the loop;
  5585. + changing a `for' statement to a `while' statement in this way can
  5586. + change the effect of the `continue' statement inside the loop.
  5587. +    There is an alternate version of the `for' loop, for iterating over
  5588. + all the indices of an array:
  5589. +      for (i in array)
  5590. +          DO SOMETHING WITH array[i]
  5591. + *Note Arrays in `awk': Arrays, for more information on this version of
  5592. + the `for' loop.
  5593. +    The `awk' language has a `for' statement in addition to a `while'
  5594. + statement because often a `for' loop is both less work to type and more
  5595. + natural to think of.  Counting the number of iterations is very common
  5596. + in loops.  It can be easier to think of this counting as part of
  5597. + looping rather than as something to do inside the loop.
  5598. +    The next section has more complicated examples of `for' loops.
  5599. + 
  5600. + File: gawk.info,  Node: Break Statement,  Next: Continue Statement,  Prev: For Statement,  Up: Statements
  5601. + The `break' Statement
  5602. + =====================
  5603. +    The `break' statement jumps out of the innermost `for', `while', or
  5604. + `do'-`while' loop that encloses it.  The following example finds the
  5605. + smallest divisor of any integer, and also identifies prime numbers:
  5606. +      awk '# find smallest divisor of num
  5607. +           { num = $1
  5608. +             for (div = 2; div*div <= num; div++)
  5609. +               if (num % div == 0)
  5610. +                 break
  5611. +             if (num % div == 0)
  5612. +               printf "Smallest divisor of %d is %d\n", num, div
  5613. +             else
  5614. +               printf "%d is prime\n", num  }'
  5615. +    When the remainder is zero in the first `if' statement, `awk'
  5616. + immediately "breaks out" of the containing `for' loop.  This means that
  5617. + `awk' proceeds immediately to the statement following the loop and
  5618. + continues processing.  (This is very different from the `exit'
  5619. + statement which stops the entire `awk' program.  *Note The `exit'
  5620. + Statement: Exit Statement.)
  5621. +    Here is another program equivalent to the previous one.  It
  5622. + illustrates how the CONDITION of a `for' or `while' could just as well
  5623. + be replaced with a `break' inside an `if':
  5624. +      awk '# find smallest divisor of num
  5625. +           { num = $1
  5626. +             for (div = 2; ; div++) {
  5627. +               if (num % div == 0) {
  5628. +                 printf "Smallest divisor of %d is %d\n", num, div
  5629. +                 break
  5630. +               }
  5631. +               if (div*div > num) {
  5632. +                 printf "%d is prime\n", num
  5633. +                 break
  5634. +               }
  5635. +             }
  5636. +      }'
  5637. + 
  5638. + File: gawk.info,  Node: Continue Statement,  Next: Next Statement,  Prev: Break Statement,  Up: Statements
  5639. + The `continue' Statement
  5640. + ========================
  5641. +    The `continue' statement, like `break', is used only inside `for',
  5642. + `while', and `do'-`while' loops.  It skips over the rest of the loop
  5643. + body, causing the next cycle around the loop to begin immediately.
  5644. + Contrast this with `break', which jumps out of the loop altogether.
  5645. + Here is an example:
  5646. +      # print names that don't contain the string "ignore"
  5647. +      
  5648. +      # first, save the text of each line
  5649. +      { names[NR] = $0 }
  5650. +      
  5651. +      # print what we're interested in
  5652. +      END {
  5653. +         for (x in names) {
  5654. +             if (names[x] ~ /ignore/)
  5655. +                 continue
  5656. +             print names[x]
  5657. +         }
  5658. +      }
  5659. +    If one of the input records contains the string `ignore', this
  5660. + example skips the print statement for that record, and continues back to
  5661. + the first statement in the loop.
  5662. +    This is not a practical example of `continue', since it would be
  5663. + just as easy to write the loop like this:
  5664. +      for (x in names)
  5665. +        if (names[x] !~ /ignore/)
  5666. +          print names[x]
  5667. +    The `continue' statement in a `for' loop directs `awk' to skip the
  5668. + rest of the body of the loop, and resume execution with the
  5669. + increment-expression of the `for' statement.  The following program
  5670. + illustrates this fact:
  5671. +      awk 'BEGIN {
  5672. +           for (x = 0; x <= 20; x++) {
  5673. +               if (x == 5)
  5674. +                   continue
  5675. +               printf ("%d ", x)
  5676. +           }
  5677. +           print ""
  5678. +      }'
  5679. + This program prints all the numbers from 0 to 20, except for 5, for
  5680. + which the `printf' is skipped.  Since the increment `x++' is not
  5681. + skipped, `x' does not remain stuck at 5.  Contrast the `for' loop above
  5682. + with the `while' loop:
  5683. +      awk 'BEGIN {
  5684. +           x = 0
  5685. +           while (x <= 20) {
  5686. +               if (x == 5)
  5687. +                   continue
  5688. +               printf ("%d ", x)
  5689. +               x++
  5690. +           }
  5691. +           print ""
  5692. +      }'
  5693. + This program loops forever once `x' gets to 5.
  5694. +    As described above, the `continue' statement has no meaning when
  5695. + used outside the body of a loop.  However, although it was never
  5696. + documented, historical implementations of `awk' have treated the
  5697. + `continue' statement outside of a loop as if it were a `next' statement
  5698. + (*note The `next' Statement: Next Statement.).  By default, `gawk'
  5699. + silently supports this usage.  However, if `-W posix' has been
  5700. + specified on the command line (*note Invoking `awk': Command Line.), it
  5701. + will be treated as an error, since the POSIX standard specifies that
  5702. + `continue' should only be used inside the body of a loop.
  5703. + 
  5704. + File: gawk.info,  Node: Next Statement,  Next: Next File Statement,  Prev: Continue Statement,  Up: Statements
  5705. + The `next' Statement
  5706. + ====================
  5707. +    The `next' statement forces `awk' to immediately stop processing the
  5708. + current record and go on to the next record.  This means that no
  5709. + further rules are executed for the current record.  The rest of the
  5710. + current rule's action is not executed either.
  5711. +    Contrast this with the effect of the `getline' function (*note
  5712. + Explicit Input with `getline': Getline.).  That too causes `awk' to
  5713. + read the next record immediately, but it does not alter the flow of
  5714. + control in any way.  So the rest of the current action executes with a
  5715. + new input record.
  5716. +    At the highest level, `awk' program execution is a loop that reads
  5717. + an input record and then tests each rule's pattern against it.  If you
  5718. + think of this loop as a `for' statement whose body contains the rules,
  5719. + then the `next' statement is analogous to a `continue' statement: it
  5720. + skips to the end of the body of this implicit loop, and executes the
  5721. + increment (which reads another record).
  5722. +    For example, if your `awk' program works only on records with four
  5723. + fields, and you don't want it to fail when given bad input, you might
  5724. + use this rule near the beginning of the program:
  5725. +      NF != 4 {
  5726. +        printf("line %d skipped: doesn't have 4 fields", FNR) > "/dev/stderr"
  5727. +        next
  5728. +      }
  5729. + so that the following rules will not see the bad record.  The error
  5730. + message is redirected to the standard error output stream, as error
  5731. + messages should be.  *Note Standard I/O Streams: Special Files.
  5732. +    According to the POSIX standard, the behavior is undefined if the
  5733. + `next' statement is used in a `BEGIN' or `END' rule.  `gawk' will treat
  5734. + it as a syntax error.
  5735. +    If the `next' statement causes the end of the input to be reached,
  5736. + then the code in the `END' rules, if any, will be executed.  *Note
  5737. + `BEGIN' and `END' Special Patterns: BEGIN/END.
  5738. + 
  5739. + File: gawk.info,  Node: Next File Statement,  Next: Exit Statement,  Prev: Next Statement,  Up: Statements
  5740. + The `next file' Statement
  5741. + =========================
  5742. +    The `next file' statement is similar to the `next' statement.
  5743. + However, instead of abandoning processing of the current record, the
  5744. + `next file' statement instructs `awk' to stop processing the current
  5745. + data file.
  5746. +    Upon execution of the `next file' statement, `FILENAME' is updated
  5747. + to the name of the next data file listed on the command line, `FNR' is
  5748. + reset to 1, and processing starts over with the first rule in the
  5749. + progam.  *Note Built-in Variables::.
  5750. +    If the `next file' statement causes the end of the input to be
  5751. + reached, then the code in the `END' rules, if any, will be executed.
  5752. + *Note `BEGIN' and `END' Special Patterns: BEGIN/END.
  5753. +    The `next file' statement is a `gawk' extension; it is not
  5754. + (currently) available in any other `awk' implementation.  You can
  5755. + simulate its behavior by creating a library file named `nextfile.awk',
  5756. + with the following contents.  (This sample program uses user-defined
  5757. + functions, a feature that has not been presented yet.  *Note
  5758. + User-defined Functions: User-defined, for more information.)
  5759. +      # nextfile --- function to skip remaining records in current file
  5760. +      
  5761. +      # this should be read in before the "main" awk program
  5762. +      
  5763. +      function nextfile() { _abandon_ = FILENAME; next }
  5764. +      
  5765. +      _abandon_ == FILENAME && FNR > 1   { next }
  5766. +      _abandon_ == FILENAME && FNR == 1  { _abandon_ = "" }
  5767. +    The `nextfile' function simply sets a "private" variable(1) to the
  5768. + name of the current data file, and then retrieves the next record.
  5769. + Since this file is read before the main `awk' program, the rules that
  5770. + follows the function definition will be executed before the rules in
  5771. + the main program.  The first rule continues to skip records as long as
  5772. + the name of the input file has not changed, and this is not the first
  5773. + record in the file.  This rule is sufficient most of the time.  But
  5774. + what if the *same* data file is named twice in a row on the command
  5775. + line?  This rule would not process the data file the second time.  The
  5776. + second rule catches this case: If the data file name is what was being
  5777. + skipped, but `FNR' is 1, then this is the second time the file is being
  5778. + processed, and it should not be skipped.
  5779. +    The `next file' statement would be useful if you have many data
  5780. + files to process, and due to the nature of the data, you expect that you
  5781. + would not want to process every record in the file.  In order to move
  5782. + on to the next data file, you would have to continue scanning the
  5783. + unwanted records (as described above).  The `next file' statement
  5784. + accomplishes this much more efficiently.
  5785. +    ---------- Footnotes ----------
  5786. +    (1)  Since all variables in `awk' are global, this program uses the
  5787. + common practice of prefixing the variable name with an underscore.  In
  5788. + fact, it also suffixes the variable name with an underscore, as extra
  5789. + insurance against using a variable name that might be used in some
  5790. + other library file.
  5791. + 
  5792. + File: gawk.info,  Node: Exit Statement,  Prev: Next File Statement,  Up: Statements
  5793. + The `exit' Statement
  5794. + ====================
  5795. +    The `exit' statement causes `awk' to immediately stop executing the
  5796. + current rule and to stop processing input; any remaining input is
  5797. + ignored.
  5798. +    If an `exit' statement is executed from a `BEGIN' rule the program
  5799. + stops processing everything immediately.  No input records are read.
  5800. + However, if an `END' rule is present, it is executed (*note `BEGIN' and
  5801. + `END' Special Patterns: BEGIN/END.).
  5802. +    If `exit' is used as part of an `END' rule, it causes the program to
  5803. + stop immediately.
  5804. +    An `exit' statement that is part of an ordinary rule (that is, not
  5805. + part of a `BEGIN' or `END' rule) stops the execution of any further
  5806. + automatic rules, but the `END' rule is executed if there is one.  If
  5807. + you do not want the `END' rule to do its job in this case, you can set
  5808. + a variable to nonzero before the `exit' statement, and check that
  5809. + variable in the `END' rule.
  5810. +    If an argument is supplied to `exit', its value is used as the exit
  5811. + status code for the `awk' process.  If no argument is supplied, `exit'
  5812. + returns status zero (success).
  5813. +    For example, let's say you've discovered an error condition you
  5814. + really don't know how to handle.  Conventionally, programs report this
  5815. + by exiting with a nonzero status.  Your `awk' program can do this using
  5816. + an `exit' statement with a nonzero argument.  Here's an example of this:
  5817. +      BEGIN {
  5818. +             if (("date" | getline date_now) < 0) {
  5819. +               print "Can't get system date" > "/dev/stderr"
  5820. +               exit 4
  5821. +             }
  5822. +      }
  5823. + 
  5824. + File: gawk.info,  Node: Arrays,  Next: Built-in,  Prev: Statements,  Up: Top
  5825. + Arrays in `awk'
  5826. + ***************
  5827. +    An "array" is a table of values, called "elements".  The elements of
  5828. + an array are distinguished by their indices.  "Indices" may be either
  5829. + numbers or strings.  Each array has a name, which looks like a variable
  5830. + name, but must not be in use as a variable name in the same `awk'
  5831. + program.
  5832. + * Menu:
  5833. + * Array Intro::                 Introduction to Arrays
  5834. + * Reference to Elements::       How to examine one element of an array.
  5835. + * Assigning Elements::          How to change an element of an array.
  5836. + * Array Example::               Basic Example of an Array
  5837. + * Scanning an Array::           A variation of the `for' statement.
  5838. +                                 It loops through the indices of
  5839. +                                 an array's existing elements.
  5840. + * Delete::                      The `delete' statement removes
  5841. +                                 an element from an array.
  5842. + * Numeric Array Subscripts::    How to use numbers as subscripts in `awk'.
  5843. + * Multi-dimensional::           Emulating multi-dimensional arrays in `awk'.
  5844. + * Multi-scanning::              Scanning multi-dimensional arrays.
  5845. + 
  5846. + File: gawk.info,  Node: Array Intro,  Next: Reference to Elements,  Prev: Arrays,  Up: Arrays
  5847. + Introduction to Arrays
  5848. + ======================
  5849. +    The `awk' language has one-dimensional "arrays" for storing groups
  5850. + of related strings or numbers.
  5851. +    Every `awk' array must have a name.  Array names have the same
  5852. + syntax as variable names; any valid variable name would also be a valid
  5853. + array name.  But you cannot use one name in both ways (as an array and
  5854. + as a variable) in one `awk' program.
  5855. +    Arrays in `awk' superficially resemble arrays in other programming
  5856. + languages; but there are fundamental differences.  In `awk', you don't
  5857. + need to specify the size of an array before you start to use it.
  5858. + Additionally, any number or string in `awk' may be used as an array
  5859. + index.
  5860. +    In most other languages, you have to "declare" an array and specify
  5861. + how many elements or components it contains.  In such languages, the
  5862. + declaration causes a contiguous block of memory to be allocated for that
  5863. + many elements.  An index in the array must be a positive integer; for
  5864. + example, the index 0 specifies the first element in the array, which is
  5865. + actually stored at the beginning of the block of memory.  Index 1
  5866. + specifies the second element, which is stored in memory right after the
  5867. + first element, and so on.  It is impossible to add more elements to the
  5868. + array, because it has room for only as many elements as you declared.
  5869. +    A contiguous array of four elements might look like this,
  5870. + conceptually, if the element values are `8', `"foo"', `""' and `30':
  5871. +      +---------+---------+--------+---------+
  5872. +      |    8    |  "foo"  |   ""   |    30   |    value
  5873. +      +---------+---------+--------+---------+
  5874. +           0         1         2         3        index
  5875. + Only the values are stored; the indices are implicit from the order of
  5876. + the values.  `8' is the value at index 0, because `8' appears in the
  5877. + position with 0 elements before it.
  5878. +    Arrays in `awk' are different: they are "associative".  This means
  5879. + that each array is a collection of pairs: an index, and its
  5880. + corresponding array element value:
  5881. +      Element 4     Value 30
  5882. +      Element 2     Value "foo"
  5883. +      Element 1     Value 8
  5884. +      Element 3     Value ""
  5885. + We have shown the pairs in jumbled order because their order is
  5886. + irrelevant.
  5887. +    One advantage of an associative array is that new pairs can be added
  5888. + at any time.  For example, suppose we add to the above array a tenth
  5889. + element whose value is `"number ten"'.  The result is this:
  5890. +      Element 10    Value "number ten"
  5891. +      Element 4     Value 30
  5892. +      Element 2     Value "foo"
  5893. +      Element 1     Value 8
  5894. +      Element 3     Value ""
  5895. + Now the array is "sparse" (i.e., some indices are missing): it has
  5896. + elements 1-4 and 10, but doesn't have elements 5, 6, 7, 8, or 9.
  5897. +    Another consequence of associative arrays is that the indices don't
  5898. + have to be positive integers.  Any number, or even a string, can be an
  5899. + index.  For example, here is an array which translates words from
  5900. + English into French:
  5901. +      Element "dog" Value "chien"
  5902. +      Element "cat" Value "chat"
  5903. +      Element "one" Value "un"
  5904. +      Element 1     Value "un"
  5905. + Here we decided to translate the number 1 in both spelled-out and
  5906. + numeric form--thus illustrating that a single array can have both
  5907. + numbers and strings as indices.
  5908. +    When `awk' creates an array for you, e.g., with the `split' built-in
  5909. + function, that array's indices are consecutive integers starting at 1.
  5910. + (*Note Built-in Functions for String Manipulation: String Functions.)
  5911. + 
  5912. + File: gawk.info,  Node: Reference to Elements,  Next: Assigning Elements,  Prev: Array Intro,  Up: Arrays
  5913. + Referring to an Array Element
  5914. + =============================
  5915. +    The principal way of using an array is to refer to one of its
  5916. + elements.  An array reference is an expression which looks like this:
  5917. +      ARRAY[INDEX]
  5918. + Here, ARRAY is the name of an array.  The expression INDEX is the index
  5919. + of the element of the array that you want.
  5920. +    The value of the array reference is the current value of that array
  5921. + element.  For example, `foo[4.3]' is an expression for the element of
  5922. + array `foo' at index 4.3.
  5923. +    If you refer to an array element that has no recorded value, the
  5924. + value of the reference is `""', the null string.  This includes elements
  5925. + to which you have not assigned any value, and elements that have been
  5926. + deleted (*note The `delete' Statement: Delete.).  Such a reference
  5927. + automatically creates that array element, with the null string as its
  5928. + value.  (In some cases, this is unfortunate, because it might waste
  5929. + memory inside `awk').
  5930. +    You can find out if an element exists in an array at a certain index
  5931. + with the expression:
  5932. +      INDEX in ARRAY
  5933. + This expression tests whether or not the particular index exists,
  5934. + without the side effect of creating that element if it is not present.
  5935. + The expression has the value 1 (true) if `ARRAY[INDEX]' exists, and 0
  5936. + (false) if it does not exist.
  5937. +    For example, to test whether the array `frequencies' contains the
  5938. + index `"2"', you could write this statement:
  5939. +      if ("2" in frequencies) print "Subscript \"2\" is present."
  5940. +    Note that this is *not* a test of whether or not the array
  5941. + `frequencies' contains an element whose *value* is `"2"'.  (There is no
  5942. + way to do that except to scan all the elements.)  Also, this *does not*
  5943. + create `frequencies["2"]', while the following (incorrect) alternative
  5944. + would do so:
  5945. +      if (frequencies["2"] != "") print "Subscript \"2\" is present."
  5946. + 
  5947. + File: gawk.info,  Node: Assigning Elements,  Next: Array Example,  Prev: Reference to Elements,  Up: Arrays
  5948. + Assigning Array Elements
  5949. + ========================
  5950. +    Array elements are lvalues: they can be assigned values just like
  5951. + `awk' variables:
  5952. +      ARRAY[SUBSCRIPT] = VALUE
  5953. + Here ARRAY is the name of your array.  The expression SUBSCRIPT is the
  5954. + index of the element of the array that you want to assign a value.  The
  5955. + expression VALUE is the value you are assigning to that element of the
  5956. + array.
  5957. + 
  5958. + File: gawk.info,  Node: Array Example,  Next: Scanning an Array,  Prev: Assigning Elements,  Up: Arrays
  5959. + Basic Example of an Array
  5960. + =========================
  5961. +    The following program takes a list of lines, each beginning with a
  5962. + line number, and prints them out in order of line number.  The line
  5963. + numbers are not in order, however, when they are first read:  they are
  5964. + scrambled.  This program sorts the lines by making an array using the
  5965. + line numbers as subscripts.  It then prints out the lines in sorted
  5966. + order of their numbers.  It is a very simple program, and gets confused
  5967. + if it encounters repeated numbers, gaps, or lines that don't begin with
  5968. + a number.
  5969. +      {
  5970. +        if ($1 > max)
  5971. +          max = $1
  5972. +        arr[$1] = $0
  5973. +      }
  5974. +      
  5975. +      END {
  5976. +        for (x = 1; x <= max; x++)
  5977. +          print arr[x]
  5978. +      }
  5979. +    The first rule keeps track of the largest line number seen so far;
  5980. + it also stores each line into the array `arr', at an index that is the
  5981. + line's number.
  5982. +    The second rule runs after all the input has been read, to print out
  5983. + all the lines.
  5984. +    When this program is run with the following input:
  5985. +      5  I am the Five man
  5986. +      2  Who are you?  The new number two!
  5987. +      4  . . . And four on the floor
  5988. +      1  Who is number one?
  5989. +      3  I three you.
  5990. + its output is this:
  5991. +      1  Who is number one?
  5992. +      2  Who are you?  The new number two!
  5993. +      3  I three you.
  5994. +      4  . . . And four on the floor
  5995. +      5  I am the Five man
  5996. +    If a line number is repeated, the last line with a given number
  5997. + overrides the others.
  5998. +    Gaps in the line numbers can be handled with an easy improvement to
  5999. + the program's `END' rule:
  6000. +      END {
  6001. +        for (x = 1; x <= max; x++)
  6002. +          if (x in arr)
  6003. +            print arr[x]
  6004. +      }
  6005. + 
  6006. + File: gawk.info,  Node: Scanning an Array,  Next: Delete,  Prev: Array Example,  Up: Arrays
  6007. + Scanning all Elements of an Array
  6008. + =================================
  6009. +    In programs that use arrays, often you need a loop that executes
  6010. + once for each element of an array.  In other languages, where arrays are
  6011. + contiguous and indices are limited to positive integers, this is easy:
  6012. + the largest index is one less than the length of the array, and you can
  6013. + find all the valid indices by counting from zero up to that value.  This
  6014. + technique won't do the job in `awk', since any number or string may be
  6015. + an array index.  So `awk' has a special kind of `for' statement for
  6016. + scanning an array:
  6017. +      for (VAR in ARRAY)
  6018. +        BODY
  6019. + This loop executes BODY once for each different value that your program
  6020. + has previously used as an index in ARRAY, with the variable VAR set to
  6021. + that index.
  6022. +    Here is a program that uses this form of the `for' statement.  The
  6023. + first rule scans the input records and notes which words appear (at
  6024. + least once) in the input, by storing a 1 into the array `used' with the
  6025. + word as index.  The second rule scans the elements of `used' to find
  6026. + all the distinct words that appear in the input.  It prints each word
  6027. + that is more than 10 characters long, and also prints the number of
  6028. + such words.  *Note Built-in Functions: Built-in, for more information
  6029. + on the built-in function `length'.
  6030. +      # Record a 1 for each word that is used at least once.
  6031. +      {
  6032. +        for (i = 1; i <= NF; i++)
  6033. +          used[$i] = 1
  6034. +      }
  6035. +      
  6036. +      # Find number of distinct words more than 10 characters long.
  6037. +      END {
  6038. +        for (x in used)
  6039. +          if (length(x) > 10) {
  6040. +            ++num_long_words
  6041. +            print x
  6042. +        }
  6043. +        print num_long_words, "words longer than 10 characters"
  6044. +      }
  6045. + *Note Sample Program::, for a more detailed example of this type.
  6046. +    The order in which elements of the array are accessed by this
  6047. + statement is determined by the internal arrangement of the array
  6048. + elements within `awk' and cannot be controlled or changed.  This can
  6049. + lead to problems if new elements are added to ARRAY by statements in
  6050. + BODY; you cannot predict whether or not the `for' loop will reach them.
  6051. + Similarly, changing VAR inside the loop can produce strange results.
  6052. + It is best to avoid such things.
  6053. + 
  6054. + File: gawk.info,  Node: Delete,  Next: Numeric Array Subscripts,  Prev: Scanning an Array,  Up: Arrays
  6055. + The `delete' Statement
  6056. + ======================
  6057. +    You can remove an individual element of an array using the `delete'
  6058. + statement:
  6059. +      delete ARRAY[INDEX]
  6060. +    You can not refer to an array element after it has been deleted; it
  6061. + is as if you had never referred to it and had never given it any value.
  6062. + You can no longer obtain any value the element once had.
  6063. +    Here is an example of deleting elements in an array:
  6064. +      for (i in frequencies)
  6065. +        delete frequencies[i]
  6066. + This example removes all the elements from the array `frequencies'.
  6067. +    If you delete an element, a subsequent `for' statement to scan the
  6068. + array will not report that element, and the `in' operator to check for
  6069. + the presence of that element will return 0:
  6070. +      delete foo[4]
  6071. +      if (4 in foo)
  6072. +        print "This will never be printed"
  6073. +    It is not an error to delete an element which does not exist.
  6074. + 
  6075. + File: gawk.info,  Node: Numeric Array Subscripts,  Next: Multi-dimensional,  Prev: Delete,  Up: Arrays
  6076. + Using Numbers to Subscript Arrays
  6077. + =================================
  6078. +    An important aspect of arrays to remember is that array subscripts
  6079. + are *always* strings.  If you use a numeric value as a subscript, it
  6080. + will be converted to a string value before it is used for subscripting
  6081. + (*note Conversion of Strings and Numbers: Conversion.).
  6082. +    This means that the value of the `CONVFMT' can potentially affect
  6083. + how your program accesses elements of an array.  For example:
  6084. +      a = b = 12.153
  6085. +      data[a] = 1
  6086. +      CONVFMT = "%2.2f"
  6087. +      if (b in data)
  6088. +          printf "%s is in data", b
  6089. +      else
  6090. +          printf "%s is not in data", b
  6091. + should print `12.15 is not in data'.  The first statement gives both
  6092. + `a' and `b' the same numeric value.  Assigning to `data[a]' first gives
  6093. + `a' the string value `"12.153"' (using the default conversion value of
  6094. + `CONVFMT', `"%.6g"'), and then assigns 1 to `data["12.153"]'.  The
  6095. + program then changes the value of `CONVFMT'.  The test `(b in data)'
  6096. + forces `b' to be converted to a string, this time `"12.15"', since the
  6097. + value of `CONVFMT' only allows two significant digits.  This test fails,
  6098. + since `"12.15"' is a different string from `"12.153"'.
  6099. +    According to the rules for conversions (*note Conversion of Strings
  6100. + and Numbers: Conversion.), integer values are always converted to
  6101. + strings as integers, no matter what the value of `CONVFMT' may happen
  6102. + to be.  So the usual case of
  6103. +      for (i = 1; i <= maxsub; i++)
  6104. +          do something with array[i]
  6105. + will work, no matter what the value of `CONVFMT'.
  6106. +    Like many things in `awk', the majority of the time things work as
  6107. + you would expect them to work.  But it is useful to have a precise
  6108. + knowledge of the actual rules, since sometimes they can have a subtle
  6109. + effect on your programs.
  6110. + 
  6111. + File: gawk.info,  Node: Multi-dimensional,  Next: Multi-scanning,  Prev: Numeric Array Subscripts,  Up: Arrays
  6112. + Multi-dimensional Arrays
  6113. + ========================
  6114. +    A multi-dimensional array is an array in which an element is
  6115. + identified by a sequence of indices, not a single index.  For example, a
  6116. + two-dimensional array requires two indices.  The usual way (in most
  6117. + languages, including `awk') to refer to an element of a two-dimensional
  6118. + array named `grid' is with `grid[X,Y]'.
  6119. +    Multi-dimensional arrays are supported in `awk' through
  6120. + concatenation of indices into one string.  What happens is that `awk'
  6121. + converts the indices into strings (*note Conversion of Strings and
  6122. + Numbers: Conversion.) and concatenates them together, with a separator
  6123. + between them.  This creates a single string that describes the values
  6124. + of the separate indices.  The combined string is used as a single index
  6125. + into an ordinary, one-dimensional array.  The separator used is the
  6126. + value of the built-in variable `SUBSEP'.
  6127. +    For example, suppose we evaluate the expression `foo[5,12]="value"'
  6128. + when the value of `SUBSEP' is `"@"'.  The numbers 5 and 12 are
  6129. + converted to strings and concatenated with an `@' between them,
  6130. + yielding `"5@12"'; thus, the array element `foo["5@12"]' is set to
  6131. + `"value"'.
  6132. +    Once the element's value is stored, `awk' has no record of whether
  6133. + it was stored with a single index or a sequence of indices.  The two
  6134. + expressions `foo[5,12]' and `foo[5 SUBSEP 12]' always have the same
  6135. + value.
  6136. +    The default value of `SUBSEP' is the string `"\034"', which contains
  6137. + a nonprinting character that is unlikely to appear in an `awk' program
  6138. + or in the input data.
  6139. +    The usefulness of choosing an unlikely character comes from the fact
  6140. + that index values that contain a string matching `SUBSEP' lead to
  6141. + combined strings that are ambiguous.  Suppose that `SUBSEP' were `"@"';
  6142. + then `foo["a@b", "c"]' and `foo["a", "b@c"]' would be indistinguishable
  6143. + because both would actually be stored as `foo["a@b@c"]'.  Because
  6144. + `SUBSEP' is `"\034"', such confusion can arise only when an index
  6145. + contains the character with ASCII code 034, which is a rare event.
  6146. +    You can test whether a particular index-sequence exists in a
  6147. + "multi-dimensional" array with the same operator `in' used for single
  6148. + dimensional arrays.  Instead of a single index as the left-hand operand,
  6149. + write the whole sequence of indices, separated by commas, in
  6150. + parentheses:
  6151. +      (SUBSCRIPT1, SUBSCRIPT2, ...) in ARRAY
  6152. +    The following example treats its input as a two-dimensional array of
  6153. + fields; it rotates this array 90 degrees clockwise and prints the
  6154. + result.  It assumes that all lines have the same number of elements.
  6155. +      awk '{
  6156. +           if (max_nf < NF)
  6157. +                max_nf = NF
  6158. +           max_nr = NR
  6159. +           for (x = 1; x <= NF; x++)
  6160. +                vector[x, NR] = $x
  6161. +      }
  6162. +      
  6163. +      END {
  6164. +           for (x = 1; x <= max_nf; x++) {
  6165. +                for (y = max_nr; y >= 1; --y)
  6166. +                     printf("%s ", vector[x, y])
  6167. +                printf("\n")
  6168. +           }
  6169. +      }'
  6170. + When given the input:
  6171. +      1 2 3 4 5 6
  6172. +      2 3 4 5 6 1
  6173. +      3 4 5 6 1 2
  6174. +      4 5 6 1 2 3
  6175. + it produces:
  6176. +      4 3 2 1
  6177. +      5 4 3 2
  6178. +      6 5 4 3
  6179. +      1 6 5 4
  6180. +      2 1 6 5
  6181. +      3 2 1 6
  6182. + 
  6183. + File: gawk.info,  Node: Multi-scanning,  Prev: Multi-dimensional,  Up: Arrays
  6184. + Scanning Multi-dimensional Arrays
  6185. + =================================
  6186. +    There is no special `for' statement for scanning a
  6187. + "multi-dimensional" array; there cannot be one, because in truth there
  6188. + are no multi-dimensional arrays or elements; there is only a
  6189. + multi-dimensional *way of accessing* an array.
  6190. +    However, if your program has an array that is always accessed as
  6191. + multi-dimensional, you can get the effect of scanning it by combining
  6192. + the scanning `for' statement (*note Scanning all Elements of an Array:
  6193. + Scanning an Array.) with the `split' built-in function (*note Built-in
  6194. + Functions for String Manipulation: String Functions.).  It works like
  6195. + this:
  6196. +      for (combined in ARRAY) {
  6197. +        split(combined, separate, SUBSEP)
  6198. +        ...
  6199. +      }
  6200. + This finds each concatenated, combined index in the array, and splits it
  6201. + into the individual indices by breaking it apart where the value of
  6202. + `SUBSEP' appears.  The split-out indices become the elements of the
  6203. + array `separate'.
  6204. +    Thus, suppose you have previously stored in `ARRAY[1, "foo"]'; then
  6205. + an element with index `"1\034foo"' exists in ARRAY.  (Recall that the
  6206. + default value of `SUBSEP' contains the character with code 034.)
  6207. + Sooner or later the `for' statement will find that index and do an
  6208. + iteration with `combined' set to `"1\034foo"'.  Then the `split'
  6209. + function is called as follows:
  6210. +      split("1\034foo", separate, "\034")
  6211. + The result of this is to set `separate[1]' to 1 and `separate[2]' to
  6212. + `"foo"'.  Presto, the original sequence of separate indices has been
  6213. + recovered.
  6214. + 
  6215. + File: gawk.info,  Node: Built-in,  Next: User-defined,  Prev: Arrays,  Up: Top
  6216. + Built-in Functions
  6217. + ******************
  6218. +    "Built-in" functions are functions that are always available for
  6219. + your `awk' program to call.  This chapter defines all the built-in
  6220. + functions in `awk'; some of them are mentioned in other sections, but
  6221. + they are summarized here for your convenience.  (You can also define
  6222. + new functions yourself.  *Note User-defined Functions: User-defined.)
  6223. + * Menu:
  6224. + * Calling Built-in::            How to call built-in functions.
  6225. + * Numeric Functions::           Functions that work with numbers,
  6226. +                                 including `int', `sin' and `rand'.
  6227. + * String Functions::            Functions for string manipulation,
  6228. +                                 such as `split', `match', and `sprintf'.
  6229. + * I/O Functions::               Functions for files and shell commands.
  6230. + * Time Functions::              Functions for dealing with time stamps.
  6231. + 
  6232. + File: gawk.info,  Node: Calling Built-in,  Next: Numeric Functions,  Prev: Built-in,  Up: Built-in
  6233. + Calling Built-in Functions
  6234. + ==========================
  6235. +    To call a built-in function, write the name of the function followed
  6236. + by arguments in parentheses.  For example, `atan2(y + z, 1)' is a call
  6237. + to the function `atan2', with two arguments.
  6238. +    Whitespace is ignored between the built-in function name and the
  6239. + open-parenthesis, but we recommend that you avoid using whitespace
  6240. + there.  User-defined functions do not permit whitespace in this way, and
  6241. + you will find it easier to avoid mistakes by following a simple
  6242. + convention which always works: no whitespace after a function name.
  6243. +    Each built-in function accepts a certain number of arguments.  In
  6244. + most cases, any extra arguments given to built-in functions are
  6245. + ignored.  The defaults for omitted arguments vary from function to
  6246. + function and are described under the individual functions.
  6247. +    When a function is called, expressions that create the function's
  6248. + actual parameters are evaluated completely before the function call is
  6249. + performed.  For example, in the code fragment:
  6250. +      i = 4
  6251. +      j = sqrt(i++)
  6252. + the variable `i' is set to 5 before `sqrt' is called with a value of 4
  6253. + for its actual parameter.
  6254. + 
  6255. + File: gawk.info,  Node: Numeric Functions,  Next: String Functions,  Prev: Calling Built-in,  Up: Built-in
  6256. + Numeric Built-in Functions
  6257. + ==========================
  6258. +    Here is a full list of built-in functions that work with numbers:
  6259. + `int(X)'
  6260. +      This gives you the integer part of X, truncated toward 0.  This
  6261. +      produces the nearest integer to X, located between X and 0.
  6262. +      For example, `int(3)' is 3, `int(3.9)' is 3, `int(-3.9)' is -3,
  6263. +      and `int(-3)' is -3 as well.
  6264. + `sqrt(X)'
  6265. +      This gives you the positive square root of X.  It reports an error
  6266. +      if X is negative.  Thus, `sqrt(4)' is 2.
  6267. + `exp(X)'
  6268. +      This gives you the exponential of X, or reports an error if X is
  6269. +      out of range.  The range of values X can have depends on your
  6270. +      machine's floating point representation.
  6271. + `log(X)'
  6272. +      This gives you the natural logarithm of X, if X is positive;
  6273. +      otherwise, it reports an error.
  6274. + `sin(X)'
  6275. +      This gives you the sine of X, with X in radians.
  6276. + `cos(X)'
  6277. +      This gives you the cosine of X, with X in radians.
  6278. + `atan2(Y, X)'
  6279. +      This gives you the arctangent of `Y / X' in radians.
  6280. + `rand()'
  6281. +      This gives you a random number.  The values of `rand' are
  6282. +      uniformly-distributed between 0 and 1.  The value is never 0 and
  6283. +      never 1.
  6284. +      Often you want random integers instead.  Here is a user-defined
  6285. +      function you can use to obtain a random nonnegative integer less
  6286. +      than N:
  6287. +           function randint(n) {
  6288. +                return int(n * rand())
  6289. +           }
  6290. +      The multiplication produces a random real number greater than 0
  6291. +      and less than N.  We then make it an integer (using `int') between
  6292. +      0 and `N - 1'.
  6293. +      Here is an example where a similar function is used to produce
  6294. +      random integers between 1 and N.  Note that this program will
  6295. +      print a new random number for each input record.
  6296. +           awk '
  6297. +           # Function to roll a simulated die.
  6298. +           function roll(n) { return 1 + int(rand() * n) }
  6299. +           
  6300. +           # Roll 3 six-sided dice and print total number of points.
  6301. +           {
  6302. +                 printf("%d points\n", roll(6)+roll(6)+roll(6))
  6303. +           }'
  6304. +      *Note:* `rand' starts generating numbers from the same point, or
  6305. +      "seed", each time you run `awk'.  This means that a program will
  6306. +      produce the same results each time you run it.  The numbers are
  6307. +      random within one `awk' run, but predictable from run to run.
  6308. +      This is convenient for debugging, but if you want a program to do
  6309. +      different things each time it is used, you must change the seed to
  6310. +      a value that will be different in each run.  To do this, use
  6311. +      `srand'.
  6312. + `srand(X)'
  6313. +      The function `srand' sets the starting point, or "seed", for
  6314. +      generating random numbers to the value X.
  6315. +      Each seed value leads to a particular sequence of "random" numbers.
  6316. +      Thus, if you set the seed to the same value a second time, you
  6317. +      will get the same sequence of "random" numbers again.
  6318. +      If you omit the argument X, as in `srand()', then the current date
  6319. +      and time of day are used for a seed.  This is the way to get random
  6320. +      numbers that are truly unpredictable.
  6321. +      The return value of `srand' is the previous seed.  This makes it
  6322. +      easy to keep track of the seeds for use in consistently reproducing
  6323. +      sequences of random numbers.
  6324. + 
  6325. + File: gawk.info,  Node: String Functions,  Next: I/O Functions,  Prev: Numeric Functions,  Up: Built-in
  6326. + Built-in Functions for String Manipulation
  6327. + ==========================================
  6328. +    The functions in this section look at or change the text of one or
  6329. + more strings.
  6330. + `index(IN, FIND)'
  6331. +      This searches the string IN for the first occurrence of the string
  6332. +      FIND, and returns the position in characters where that occurrence
  6333. +      begins in the string IN.  For example:
  6334. +           awk 'BEGIN { print index("peanut", "an") }'
  6335. +      prints `3'.  If FIND is not found, `index' returns 0.  (Remember
  6336. +      that string indices in `awk' start at 1.)
  6337. + `length(STRING)'
  6338. +      This gives you the number of characters in STRING.  If STRING is a
  6339. +      number, the length of the digit string representing that number is
  6340. +      returned.  For example, `length("abcde")' is 5.  By contrast,
  6341. +      `length(15 * 35)' works out to 3.  How?  Well, 15 * 35 = 525, and
  6342. +      525 is then converted to the string `"525"', which has three
  6343. +      characters.
  6344. +      If no argument is supplied, `length' returns the length of `$0'.
  6345. +      In older versions of `awk', you could call the `length' function
  6346. +      without any parentheses.  Doing so is marked as "deprecated" in the
  6347. +      POSIX standard.  This means that while you can do this in your
  6348. +      programs, it is a feature that can eventually be removed from a
  6349. +      future version of the standard.  Therefore, for maximal
  6350. +      portability of your `awk' programs you should always supply the
  6351. +      parentheses.
  6352. + `match(STRING, REGEXP)'
  6353. +      The `match' function searches the string, STRING, for the longest,
  6354. +      leftmost substring matched by the regular expression, REGEXP.  It
  6355. +      returns the character position, or "index", of where that
  6356. +      substring begins (1, if it starts at the beginning of STRING).  If
  6357. +      no match if found, it returns 0.
  6358. +      The `match' function sets the built-in variable `RSTART' to the
  6359. +      index.  It also sets the built-in variable `RLENGTH' to the length
  6360. +      in characters of the matched substring.  If no match is found,
  6361. +      `RSTART' is set to 0, and `RLENGTH' to -1.
  6362. +      For example:
  6363. +           awk '{
  6364. +                  if ($1 == "FIND")
  6365. +                    regex = $2
  6366. +                  else {
  6367. +                    where = match($0, regex)
  6368. +                    if (where)
  6369. +                      print "Match of", regex, "found at", where, "in", $0
  6370. +                  }
  6371. +           }'
  6372. +      This program looks for lines that match the regular expression
  6373. +      stored in the variable `regex'.  This regular expression can be
  6374. +      changed.  If the first word on a line is `FIND', `regex' is
  6375. +      changed to be the second word on that line.  Therefore, given:
  6376. +           FIND fo*bar
  6377. +           My program was a foobar
  6378. +           But none of it would doobar
  6379. +           FIND Melvin
  6380. +           JF+KM
  6381. +           This line is property of The Reality Engineering Co.
  6382. +           This file created by Melvin.
  6383. +      `awk' prints:
  6384. +           Match of fo*bar found at 18 in My program was a foobar
  6385. +           Match of Melvin found at 26 in This file created by Melvin.
  6386. + `split(STRING, ARRAY, FIELDSEP)'
  6387. +      This divides STRING into pieces separated by FIELDSEP, and stores
  6388. +      the pieces in ARRAY.  The first piece is stored in `ARRAY[1]', the
  6389. +      second piece in `ARRAY[2]', and so forth.  The string value of the
  6390. +      third argument, FIELDSEP, is a regexp describing where to split
  6391. +      STRING (much as `FS' can be a regexp describing where to split
  6392. +      input records).  If the FIELDSEP is omitted, the value of `FS' is
  6393. +      used.  `split' returns the number of elements created.
  6394. +      The `split' function, then, splits strings into pieces in a manner
  6395. +      similar to the way input lines are split into fields.  For example:
  6396. +           split("auto-da-fe", a, "-")
  6397. +      splits the string `auto-da-fe' into three fields using `-' as the
  6398. +      separator.  It sets the contents of the array `a' as follows:
  6399. +           a[1] = "auto"
  6400. +           a[2] = "da"
  6401. +           a[3] = "fe"
  6402. +      The value returned by this call to `split' is 3.
  6403. +      As with input field-splitting, when the value of FIELDSEP is `"
  6404. +      "', leading and trailing whitespace is ignored, and the elements
  6405. +      are separated by runs of whitespace.
  6406. + `sprintf(FORMAT, EXPRESSION1,...)'
  6407. +      This returns (without printing) the string that `printf' would
  6408. +      have printed out with the same arguments (*note Using `printf'
  6409. +      Statements for Fancier Printing: Printf.).  For example:
  6410. +           sprintf("pi = %.2f (approx.)", 22/7)
  6411. +      returns the string `"pi = 3.14 (approx.)"'.
  6412. + `sub(REGEXP, REPLACEMENT, TARGET)'
  6413. +      The `sub' function alters the value of TARGET.  It searches this
  6414. +      value, which should be a string, for the leftmost substring
  6415. +      matched by the regular expression, REGEXP, extending this match as
  6416. +      far as possible.  Then the entire string is changed by replacing
  6417. +      the matched text with REPLACEMENT.  The modified string becomes
  6418. +      the new value of TARGET.
  6419. +      This function is peculiar because TARGET is not simply used to
  6420. +      compute a value, and not just any expression will do: it must be a
  6421. +      variable, field or array reference, so that `sub' can store a
  6422. +      modified value there.  If this argument is omitted, then the
  6423. +      default is to use and alter `$0'.
  6424. +      For example:
  6425. +           str = "water, water, everywhere"
  6426. +           sub(/at/, "ith", str)
  6427. +      sets `str' to `"wither, water, everywhere"', by replacing the
  6428. +      leftmost, longest occurrence of `at' with `ith'.
  6429. +      The `sub' function returns the number of substitutions made (either
  6430. +      one or zero).
  6431. +      If the special character `&' appears in REPLACEMENT, it stands for
  6432. +      the precise substring that was matched by REGEXP.  (If the regexp
  6433. +      can match more than one string, then this precise substring may
  6434. +      vary.)  For example:
  6435. +           awk '{ sub(/candidate/, "& and his wife"); print }'
  6436. +      changes the first occurrence of `candidate' to `candidate and his
  6437. +      wife' on each input line.
  6438. +      Here is another example:
  6439. +           awk 'BEGIN {
  6440. +                   str = "daabaaa"
  6441. +                   sub(/a*/, "c&c", str)
  6442. +                   print str
  6443. +           }'
  6444. +      prints `dcaacbaaa'.  This show how `&' can represent a non-constant
  6445. +      string, and also illustrates the "leftmost, longest" rule.
  6446. +      The effect of this special character (`&') can be turned off by
  6447. +      putting a backslash before it in the string.  As usual, to insert
  6448. +      one backslash in the string, you must write two backslashes.
  6449. +      Therefore, write `\\&' in a string constant to include a literal
  6450. +      `&' in the replacement.  For example, here is how to replace the
  6451. +      first `|' on each line with an `&':
  6452. +           awk '{ sub(/\|/, "\\&"); print }'
  6453. +      *Note:* as mentioned above, the third argument to `sub' must be an
  6454. +      lvalue.  Some versions of `awk' allow the third argument to be an
  6455. +      expression which is not an lvalue.  In such a case, `sub' would
  6456. +      still search for the pattern and return 0 or 1, but the result of
  6457. +      the substitution (if any) would be thrown away because there is no
  6458. +      place to put it.  Such versions of `awk' accept expressions like
  6459. +      this:
  6460. +           sub(/USA/, "United States", "the USA and Canada")
  6461. +      But that is considered erroneous in `gawk'.
  6462. + `gsub(REGEXP, REPLACEMENT, TARGET)'
  6463. +      This is similar to the `sub' function, except `gsub' replaces
  6464. +      *all* of the longest, leftmost, *nonoverlapping* matching
  6465. +      substrings it can find.  The `g' in `gsub' stands for "global,"
  6466. +      which means replace everywhere.  For example:
  6467. +           awk '{ gsub(/Britain/, "United Kingdom"); print }'
  6468. +      replaces all occurrences of the string `Britain' with `United
  6469. +      Kingdom' for all input records.
  6470. +      The `gsub' function returns the number of substitutions made.  If
  6471. +      the variable to be searched and altered, TARGET, is omitted, then
  6472. +      the entire input record, `$0', is used.
  6473. +      As in `sub', the characters `&' and `\' are special, and the third
  6474. +      argument must be an lvalue.
  6475. + `substr(STRING, START, LENGTH)'
  6476. +      This returns a LENGTH-character-long substring of STRING, starting
  6477. +      at character number START.  The first character of a string is
  6478. +      character number one.  For example, `substr("washington", 5, 3)'
  6479. +      returns `"ing"'.
  6480. +      If LENGTH is not present, this function returns the whole suffix of
  6481. +      STRING that begins at character number START.  For example,
  6482. +      `substr("washington", 5)' returns `"ington"'.  This is also the
  6483. +      case if LENGTH is greater than the number of characters remaining
  6484. +      in the string, counting from character number START.
  6485. + `tolower(STRING)'
  6486. +      This returns a copy of STRING, with each upper-case character in
  6487. +      the string replaced with its corresponding lower-case character.
  6488. +      Nonalphabetic characters are left unchanged.  For example,
  6489. +      `tolower("MiXeD cAsE 123")' returns `"mixed case 123"'.
  6490. + `toupper(STRING)'
  6491. +      This returns a copy of STRING, with each lower-case character in
  6492. +      the string replaced with its corresponding upper-case character.
  6493. +      Nonalphabetic characters are left unchanged.  For example,
  6494. +      `toupper("MiXeD cAsE 123")' returns `"MIXED CASE 123"'.
  6495. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-6 gawk-2.15.5/gawk.info-6
  6496. *** /src/baseline/gawk-2.15.5/gawk.info-6    Thu Jan  1 00:00:00 1970
  6497. --- gawk-2.15.5/gawk.info-6    Sun Jun 12 22:28:53 1994
  6498. ***************
  6499. *** 0 ****
  6500. --- 1,1234 ----
  6501. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  6502. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  6503. +    This file documents `awk', a program that you can use to select
  6504. + particular records in a file and perform operations upon them.
  6505. +    This is Edition 0.15 of `The GAWK Manual',
  6506. + for the 2.15 version of the GNU implementation
  6507. + of AWK.
  6508. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  6509. +    Permission is granted to make and distribute verbatim copies of this
  6510. + manual provided the copyright notice and this permission notice are
  6511. + preserved on all copies.
  6512. +    Permission is granted to copy and distribute modified versions of
  6513. + this manual under the conditions for verbatim copying, provided that
  6514. + the entire resulting derived work is distributed under the terms of a
  6515. + permission notice identical to this one.
  6516. +    Permission is granted to copy and distribute translations of this
  6517. + manual into another language, under the above conditions for modified
  6518. + versions, except that this permission notice may be stated in a
  6519. + translation approved by the Foundation.
  6520. + 
  6521. + File: gawk.info,  Node: I/O Functions,  Next: Time Functions,  Prev: String Functions,  Up: Built-in
  6522. + Built-in Functions for Input/Output
  6523. + ===================================
  6524. + `close(FILENAME)'
  6525. +      Close the file FILENAME, for input or output.  The argument may
  6526. +      alternatively be a shell command that was used for redirecting to
  6527. +      or from a pipe; then the pipe is closed.
  6528. +      *Note Closing Input Files and Pipes: Close Input, regarding closing
  6529. +      input files and pipes.  *Note Closing Output Files and Pipes:
  6530. +      Close Output, regarding closing output files and pipes.
  6531. + `system(COMMAND)'
  6532. +      The system function allows the user to execute operating system
  6533. +      commands and then return to the `awk' program.  The `system'
  6534. +      function executes the command given by the string COMMAND.  It
  6535. +      returns, as its value, the status returned by the command that was
  6536. +      executed.
  6537. +      For example, if the following fragment of code is put in your `awk'
  6538. +      program:
  6539. +           END {
  6540. +                system("mail -s 'awk run done' operator < /dev/null")
  6541. +           }
  6542. +      the system operator will be sent mail when the `awk' program
  6543. +      finishes processing input and begins its end-of-input processing.
  6544. +      Note that much the same result can be obtained by redirecting
  6545. +      `print' or `printf' into a pipe.  However, if your `awk' program
  6546. +      is interactive, `system' is useful for cranking up large
  6547. +      self-contained programs, such as a shell or an editor.
  6548. +      Some operating systems cannot implement the `system' function.
  6549. +      `system' causes a fatal error if it is not supported.
  6550. + Controlling Output Buffering with `system'
  6551. + ------------------------------------------
  6552. +    Many utility programs will "buffer" their output; they save
  6553. + information to be written to a disk file or terminal in memory, until
  6554. + there is enough to be written in one operation.  This is often more
  6555. + efficient than writing every little bit of information as soon as it is
  6556. + ready.  However, sometimes it is necessary to force a program to
  6557. + "flush" its buffers; that is, write the information to its destination,
  6558. + even if a buffer is not full.  You can do this from your `awk' program
  6559. + by calling `system' with a null string as its argument:
  6560. +      system("")   # flush output
  6561. + `gawk' treats this use of the `system' function as a special case, and
  6562. + is smart enough not to run a shell (or other command interpreter) with
  6563. + the empty command.  Therefore, with `gawk', this idiom is not only
  6564. + useful, it is efficient.  While this idiom should work with other `awk'
  6565. + implementations, it will not necessarily avoid starting an unnecessary
  6566. + shell.
  6567. + 
  6568. + File: gawk.info,  Node: Time Functions,  Prev: I/O Functions,  Up: Built-in
  6569. + Functions for Dealing with Time Stamps
  6570. + ======================================
  6571. +    A common use for `awk' programs is the processing of log files.  Log
  6572. + files often contain time stamp information, indicating when a
  6573. + particular log record was written.  Many programs log their time stamp
  6574. + in the form returned by the `time' system call, which is the number of
  6575. + seconds since a particular epoch.  On POSIX systems, it is the number
  6576. + of seconds since Midnight, January 1, 1970, UTC.
  6577. +    In order to make it easier to process such log files, and to easily
  6578. + produce useful reports, `gawk' provides two functions for working with
  6579. + time stamps.  Both of these are `gawk' extensions; they are not
  6580. + specified in the POSIX standard, nor are they in any other known version
  6581. + of `awk'.
  6582. + `systime()'
  6583. +      This function returns the current time as the number of seconds
  6584. +      since the system epoch.  On POSIX systems, this is the number of
  6585. +      seconds since Midnight, January 1, 1970, UTC.  It may be a
  6586. +      different number on other systems.
  6587. + `strftime(FORMAT, TIMESTAMP)'
  6588. +      This function returns a string.  It is similar to the function of
  6589. +      the same name in the ANSI C standard library.  The time specified
  6590. +      by TIMESTAMP is used to produce a string, based on the contents of
  6591. +      the FORMAT string.
  6592. +    The `systime' function allows you to compare a time stamp from a log
  6593. + file with the current time of day.  In particular, it is easy to
  6594. + determine how long ago a particular record was logged.  It also allows
  6595. + you to produce log records using the "seconds since the epoch" format.
  6596. +    The `strftime' function allows you to easily turn a time stamp into
  6597. + human-readable information.  It is similar in nature to the `sprintf'
  6598. + function, copying non-format specification characters verbatim to the
  6599. + returned string, and substituting date and time values for format
  6600. + specifications in the FORMAT string.  If no TIMESTAMP argument is
  6601. + supplied, `gawk' will use the current time of day as the time stamp.
  6602. +    `strftime' is guaranteed by the ANSI C standard to support the
  6603. + following date format specifications:
  6604. + `%a'
  6605. +      The locale's abbreviated weekday name.
  6606. + `%A'
  6607. +      The locale's full weekday name.
  6608. + `%b'
  6609. +      The locale's abbreviated month name.
  6610. + `%B'
  6611. +      The locale's full month name.
  6612. + `%c'
  6613. +      The locale's "appropriate" date and time representation.
  6614. + `%d'
  6615. +      The day of the month as a decimal number (01-31).
  6616. + `%H'
  6617. +      The hour (24-hour clock) as a decimal number (00-23).
  6618. + `%I'
  6619. +      The hour (12-hour clock) as a decimal number (01-12).
  6620. + `%j'
  6621. +      The day of the year as a decimal number (001-366).
  6622. + `%m'
  6623. +      The month as a decimal number (01-12).
  6624. + `%M'
  6625. +      The minute as a decimal number (00-59).
  6626. + `%p'
  6627. +      The locale's equivalent of the AM/PM designations associated with
  6628. +      a 12-hour clock.
  6629. + `%S'
  6630. +      The second as a decimal number (00-61).  (Occasionally there are
  6631. +      minutes in a year with one or two leap seconds, which is why the
  6632. +      seconds can go from 0 all the way to 61.)
  6633. + `%U'
  6634. +      The week number of the year (the first Sunday as the first day of
  6635. +      week 1) as a decimal number (00-53).
  6636. + `%w'
  6637. +      The weekday as a decimal number (0-6).  Sunday is day 0.
  6638. + `%W'
  6639. +      The week number of the year (the first Monday as the first day of
  6640. +      week 1) as a decimal number (00-53).
  6641. + `%x'
  6642. +      The locale's "appropriate" date representation.
  6643. + `%X'
  6644. +      The locale's "appropriate" time representation.
  6645. + `%y'
  6646. +      The year without century as a decimal number (00-99).
  6647. + `%Y'
  6648. +      The year with century as a decimal number.
  6649. + `%Z'
  6650. +      The time zone name or abbreviation, or no characters if no time
  6651. +      zone is determinable.
  6652. + `%%'
  6653. +      A literal `%'.
  6654. +    If a conversion specifier is not one of the above, the behavior is
  6655. + undefined.  (This is because the ANSI standard for C leaves the
  6656. + behavior of the C version of `strftime' undefined, and `gawk' will use
  6657. + the system's version of `strftime' if it's there.  Typically, the
  6658. + conversion specifier will either not appear in the returned string, or
  6659. + it will appear literally.)
  6660. +    Informally, a "locale" is the geographic place in which a program is
  6661. + meant to run.  For example, a common way to abbreviate the date
  6662. + September 4, 1991 in the United States would be "9/4/91".  In many
  6663. + countries in Europe, however, it would be abbreviated "4.9.91".  Thus,
  6664. + the `%x' specification in a `"US"' locale might produce `9/4/91', while
  6665. + in a `"EUROPE"' locale, it might produce `4.9.91'.  The ANSI C standard
  6666. + defines a default `"C"' locale, which is an environment that is typical
  6667. + of what most C programmers are used to.
  6668. +    A public-domain C version of `strftime' is shipped with `gawk' for
  6669. + systems that are not yet fully ANSI-compliant.  If that version is used
  6670. + to compile `gawk' (*note Installing `gawk': Installation.), then the
  6671. + following additional format specifications are available:
  6672. + `%D'
  6673. +      Equivalent to specifying `%m/%d/%y'.
  6674. + `%e'
  6675. +      The day of the month, padded with a blank if it is only one digit.
  6676. + `%h'
  6677. +      Equivalent to `%b', above.
  6678. + `%n'
  6679. +      A newline character (ASCII LF).
  6680. + `%r'
  6681. +      Equivalent to specifying `%I:%M:%S %p'.
  6682. + `%R'
  6683. +      Equivalent to specifying `%H:%M'.
  6684. + `%T'
  6685. +      Equivalent to specifying `%H:%M:%S'.
  6686. + `%t'
  6687. +      A TAB character.
  6688. + `%k'
  6689. +      is replaced by the hour (24-hour clock) as a decimal number (0-23).
  6690. +      Single digit numbers are padded with a blank.
  6691. + `%l'
  6692. +      is replaced by the hour (12-hour clock) as a decimal number (1-12).
  6693. +      Single digit numbers are padded with a blank.
  6694. + `%C'
  6695. +      The century, as a number between 00 and 99.
  6696. + `%u'
  6697. +      is replaced by the weekday as a decimal number [1 (Monday)-7].
  6698. + `%V'
  6699. +      is replaced by the week number of the year (the first Monday as
  6700. +      the first day of week 1) as a decimal number (01-53).  The method
  6701. +      for determining the week number is as specified by ISO 8601 (to
  6702. +      wit: if the week containing January 1 has four or more days in the
  6703. +      new year, then it is week 1, otherwise it is week 53 of the
  6704. +      previous year and the next week is week 1).
  6705. + `%Ec %EC %Ex %Ey %EY %Od %Oe %OH %OI'
  6706. + `%Om %OM %OS %Ou %OU %OV %Ow %OW %Oy'
  6707. +      These are "alternate representations" for the specifications that
  6708. +      use only the second letter (`%c', `%C', and so on).  They are
  6709. +      recognized, but their normal representations are used.  (These
  6710. +      facilitate compliance with the POSIX `date' utility.)
  6711. + `%v'
  6712. +      The date in VMS format (e.g. 20-JUN-1991).
  6713. +    Here are two examples that use `strftime'.  The first is an `awk'
  6714. + version of the C `ctime' function.  (This is a user defined function,
  6715. + which we have not discussed yet.  *Note User-defined Functions:
  6716. + User-defined, for more information.)
  6717. +      # ctime.awk
  6718. +      #
  6719. +      # awk version of C ctime(3) function
  6720. +      
  6721. +      function ctime(ts,    format)
  6722. +      {
  6723. +          format = "%a %b %e %H:%M:%S %Z %Y"
  6724. +          if (ts == 0)
  6725. +              ts = systime()         # use current time as default
  6726. +          return strftime(format, ts)
  6727. +      }
  6728. +    This next example is an `awk' implementation of the POSIX `date'
  6729. + utility.  Normally, the `date' utility prints the current date and time
  6730. + of day in a well known format.  However, if you provide an argument to
  6731. + it that begins with a `+', `date' will copy non-format specifier
  6732. + characters to the standard output, and will interpret the current time
  6733. + according to the format specifiers in the string.  For example:
  6734. +      date '+Today is %A, %B %d, %Y.'
  6735. + might print
  6736. +      Today is Thursday, July 11, 1991.
  6737. +    Here is the `awk' version of the `date' utility.
  6738. +      #! /bin/gawk -f
  6739. +      #
  6740. +      # date --- implement the P1003.2 Draft 11 'date' command
  6741. +      #
  6742. +      # Bug: does not recognize the -u argument.
  6743. +      
  6744. +      BEGIN    \
  6745. +      {
  6746. +          format = "%a %b %e %H:%M:%S %Z %Y"
  6747. +          exitval = 0
  6748. +      
  6749. +          if (ARGC > 2)
  6750. +              exitval = 1
  6751. +          else if (ARGC == 2) {
  6752. +              format = ARGV[1]
  6753. +              if (format ~ /^\+/)
  6754. +                  format = substr(format, 2)    # remove leading +
  6755. +          }
  6756. +          print strftime(format)
  6757. +          exit exitval
  6758. +      }
  6759. + 
  6760. + File: gawk.info,  Node: User-defined,  Next: Built-in Variables,  Prev: Built-in,  Up: Top
  6761. + User-defined Functions
  6762. + **********************
  6763. +    Complicated `awk' programs can often be simplified by defining your
  6764. + own functions.  User-defined functions can be called just like built-in
  6765. + ones (*note Function Calls::.), but it is up to you to define them--to
  6766. + tell `awk' what they should do.
  6767. + * Menu:
  6768. + * Definition Syntax::           How to write definitions and what they mean.
  6769. + * Function Example::            An example function definition and
  6770. +                                 what it does.
  6771. + * Function Caveats::            Things to watch out for.
  6772. + * Return Statement::            Specifying the value a function returns.
  6773. + 
  6774. + File: gawk.info,  Node: Definition Syntax,  Next: Function Example,  Prev: User-defined,  Up: User-defined
  6775. + Syntax of Function Definitions
  6776. + ==============================
  6777. +    Definitions of functions can appear anywhere between the rules of the
  6778. + `awk' program.  Thus, the general form of an `awk' program is extended
  6779. + to include sequences of rules *and* user-defined function definitions.
  6780. +    The definition of a function named NAME looks like this:
  6781. +      function NAME (PARAMETER-LIST) {
  6782. +           BODY-OF-FUNCTION
  6783. +      }
  6784. + NAME is the name of the function to be defined.  A valid function name
  6785. + is like a valid variable name: a sequence of letters, digits and
  6786. + underscores, not starting with a digit.  Functions share the same pool
  6787. + of names as variables and arrays.
  6788. +    PARAMETER-LIST is a list of the function's arguments and local
  6789. + variable names, separated by commas.  When the function is called, the
  6790. + argument names are used to hold the argument values given in the call.
  6791. + The local variables are initialized to the null string.
  6792. +    The BODY-OF-FUNCTION consists of `awk' statements.  It is the most
  6793. + important part of the definition, because it says what the function
  6794. + should actually *do*.  The argument names exist to give the body a way
  6795. + to talk about the arguments; local variables, to give the body places
  6796. + to keep temporary values.
  6797. +    Argument names are not distinguished syntactically from local
  6798. + variable names; instead, the number of arguments supplied when the
  6799. + function is called determines how many argument variables there are.
  6800. + Thus, if three argument values are given, the first three names in
  6801. + PARAMETER-LIST are arguments, and the rest are local variables.
  6802. +    It follows that if the number of arguments is not the same in all
  6803. + calls to the function, some of the names in PARAMETER-LIST may be
  6804. + arguments on some occasions and local variables on others.  Another way
  6805. + to think of this is that omitted arguments default to the null string.
  6806. +    Usually when you write a function you know how many names you intend
  6807. + to use for arguments and how many you intend to use as locals.  By
  6808. + convention, you should write an extra space between the arguments and
  6809. + the locals, so other people can follow how your function is supposed to
  6810. + be used.
  6811. +    During execution of the function body, the arguments and local
  6812. + variable values hide or "shadow" any variables of the same names used
  6813. + in the rest of the program.  The shadowed variables are not accessible
  6814. + in the function definition, because there is no way to name them while
  6815. + their names have been taken away for the local variables.  All other
  6816. + variables used in the `awk' program can be referenced or set normally
  6817. + in the function definition.
  6818. +    The arguments and local variables last only as long as the function
  6819. + body is executing.  Once the body finishes, the shadowed variables come
  6820. + back.
  6821. +    The function body can contain expressions which call functions.  They
  6822. + can even call this function, either directly or by way of another
  6823. + function.  When this happens, we say the function is "recursive".
  6824. +    There is no need in `awk' to put the definition of a function before
  6825. + all uses of the function.  This is because `awk' reads the entire
  6826. + program before starting to execute any of it.
  6827. +    In many `awk' implementations, the keyword `function' may be
  6828. + abbreviated `func'.  However, POSIX only specifies the use of the
  6829. + keyword `function'.  This actually has some practical implications.  If
  6830. + `gawk' is in POSIX-compatibility mode (*note Invoking `awk': Command
  6831. + Line.), then the following statement will *not* define a function:
  6832. +      func foo() { a = sqrt($1) ; print a }
  6833. + Instead it defines a rule that, for each record, concatenates the value
  6834. + of the variable `func' with the return value of the function `foo', and
  6835. + based on the truth value of the result, executes the corresponding
  6836. + action.  This is probably not what was desired.  (`awk' accepts this
  6837. + input as syntactically valid, since functions may be used before they
  6838. + are defined in `awk' programs.)
  6839. + 
  6840. + File: gawk.info,  Node: Function Example,  Next: Function Caveats,  Prev: Definition Syntax,  Up: User-defined
  6841. + Function Definition Example
  6842. + ===========================
  6843. +    Here is an example of a user-defined function, called `myprint', that
  6844. + takes a number and prints it in a specific format.
  6845. +      function myprint(num)
  6846. +      {
  6847. +           printf "%6.3g\n", num
  6848. +      }
  6849. + To illustrate, here is an `awk' rule which uses our `myprint' function:
  6850. +      $3 > 0     { myprint($3) }
  6851. + This program prints, in our special format, all the third fields that
  6852. + contain a positive number in our input.  Therefore, when given:
  6853. +       1.2   3.4    5.6   7.8
  6854. +       9.10 11.12 -13.14 15.16
  6855. +      17.18 19.20  21.22 23.24
  6856. + this program, using our function to format the results, prints:
  6857. +         5.6
  6858. +        21.2
  6859. +    Here is a rather contrived example of a recursive function.  It
  6860. + prints a string backwards:
  6861. +      function rev (str, len) {
  6862. +          if (len == 0) {
  6863. +              printf "\n"
  6864. +              return
  6865. +          }
  6866. +          printf "%c", substr(str, len, 1)
  6867. +          rev(str, len - 1)
  6868. +      }
  6869. + 
  6870. + File: gawk.info,  Node: Function Caveats,  Next: Return Statement,  Prev: Function Example,  Up: User-defined
  6871. + Calling User-defined Functions
  6872. + ==============================
  6873. +    "Calling a function" means causing the function to run and do its
  6874. + job.  A function call is an expression, and its value is the value
  6875. + returned by the function.
  6876. +    A function call consists of the function name followed by the
  6877. + arguments in parentheses.  What you write in the call for the arguments
  6878. + are `awk' expressions; each time the call is executed, these
  6879. + expressions are evaluated, and the values are the actual arguments.  For
  6880. + example, here is a call to `foo' with three arguments (the first being
  6881. + a string concatenation):
  6882. +      foo(x y, "lose", 4 * z)
  6883. +      *Caution:* whitespace characters (spaces and tabs) are not allowed
  6884. +      between the function name and the open-parenthesis of the argument
  6885. +      list.  If you write whitespace by mistake, `awk' might think that
  6886. +      you mean to concatenate a variable with an expression in
  6887. +      parentheses.  However, it notices that you used a function name
  6888. +      and not a variable name, and reports an error.
  6889. +    When a function is called, it is given a *copy* of the values of its
  6890. + arguments.  This is called "call by value".  The caller may use a
  6891. + variable as the expression for the argument, but the called function
  6892. + does not know this: it only knows what value the argument had.  For
  6893. + example, if you write this code:
  6894. +      foo = "bar"
  6895. +      z = myfunc(foo)
  6896. + then you should not think of the argument to `myfunc' as being "the
  6897. + variable `foo'."  Instead, think of the argument as the string value,
  6898. + `"bar"'.
  6899. +    If the function `myfunc' alters the values of its local variables,
  6900. + this has no effect on any other variables.  In particular, if `myfunc'
  6901. + does this:
  6902. +      function myfunc (win) {
  6903. +        print win
  6904. +        win = "zzz"
  6905. +        print win
  6906. +      }
  6907. + to change its first argument variable `win', this *does not* change the
  6908. + value of `foo' in the caller.  The role of `foo' in calling `myfunc'
  6909. + ended when its value, `"bar"', was computed.  If `win' also exists
  6910. + outside of `myfunc', the function body cannot alter this outer value,
  6911. + because it is shadowed during the execution of `myfunc' and cannot be
  6912. + seen or changed from there.
  6913. +    However, when arrays are the parameters to functions, they are *not*
  6914. + copied.  Instead, the array itself is made available for direct
  6915. + manipulation by the function.  This is usually called "call by
  6916. + reference".  Changes made to an array parameter inside the body of a
  6917. + function *are* visible outside that function.  This can be *very*
  6918. + dangerous if you do not watch what you are doing.  For example:
  6919. +      function changeit (array, ind, nvalue) {
  6920. +           array[ind] = nvalue
  6921. +      }
  6922. +      
  6923. +      BEGIN {
  6924. +                 a[1] = 1 ; a[2] = 2 ; a[3] = 3
  6925. +                 changeit(a, 2, "two")
  6926. +                 printf "a[1] = %s, a[2] = %s, a[3] = %s\n", a[1], a[2], a[3]
  6927. +            }
  6928. + prints `a[1] = 1, a[2] = two, a[3] = 3', because calling `changeit'
  6929. + stores `"two"' in the second element of `a'.
  6930. + 
  6931. + File: gawk.info,  Node: Return Statement,  Prev: Function Caveats,  Up: User-defined
  6932. + The `return' Statement
  6933. + ======================
  6934. +    The body of a user-defined function can contain a `return' statement.
  6935. + This statement returns control to the rest of the `awk' program.  It
  6936. + can also be used to return a value for use in the rest of the `awk'
  6937. + program.  It looks like this:
  6938. +      return EXPRESSION
  6939. +    The EXPRESSION part is optional.  If it is omitted, then the returned
  6940. + value is undefined and, therefore, unpredictable.
  6941. +    A `return' statement with no value expression is assumed at the end
  6942. + of every function definition.  So if control reaches the end of the
  6943. + function body, then the function returns an unpredictable value.  `awk'
  6944. + will not warn you if you use the return value of such a function; you
  6945. + will simply get unpredictable or unexpected results.
  6946. +    Here is an example of a user-defined function that returns a value
  6947. + for the largest number among the elements of an array:
  6948. +      function maxelt (vec,   i, ret) {
  6949. +           for (i in vec) {
  6950. +                if (ret == "" || vec[i] > ret)
  6951. +                     ret = vec[i]
  6952. +           }
  6953. +           return ret
  6954. +      }
  6955. + You call `maxelt' with one argument, which is an array name.  The local
  6956. + variables `i' and `ret' are not intended to be arguments; while there
  6957. + is nothing to stop you from passing two or three arguments to `maxelt',
  6958. + the results would be strange.  The extra space before `i' in the
  6959. + function parameter list is to indicate that `i' and `ret' are not
  6960. + supposed to be arguments.  This is a convention which you should follow
  6961. + when you define functions.
  6962. +    Here is a program that uses our `maxelt' function.  It loads an
  6963. + array, calls `maxelt', and then reports the maximum number in that
  6964. + array:
  6965. +      awk '
  6966. +      function maxelt (vec,   i, ret) {
  6967. +           for (i in vec) {
  6968. +                if (ret == "" || vec[i] > ret)
  6969. +                     ret = vec[i]
  6970. +           }
  6971. +           return ret
  6972. +      }
  6973. +      
  6974. +      # Load all fields of each record into nums.
  6975. +      {
  6976. +                for(i = 1; i <= NF; i++)
  6977. +                     nums[NR, i] = $i
  6978. +      }
  6979. +      
  6980. +      END {
  6981. +           print maxelt(nums)
  6982. +      }'
  6983. +    Given the following input:
  6984. +       1 5 23 8 16
  6985. +      44 3 5 2 8 26
  6986. +      256 291 1396 2962 100
  6987. +      -6 467 998 1101
  6988. +      99385 11 0 225
  6989. + our program tells us (predictably) that:
  6990. +      99385
  6991. + is the largest number in our array.
  6992. + 
  6993. + File: gawk.info,  Node: Built-in Variables,  Next: Command Line,  Prev: User-defined,  Up: Top
  6994. + Built-in Variables
  6995. + ******************
  6996. +    Most `awk' variables are available for you to use for your own
  6997. + purposes; they never change except when your program assigns values to
  6998. + them, and never affect anything except when your program examines them.
  6999. +    A few variables have special built-in meanings.  Some of them `awk'
  7000. + examines automatically, so that they enable you to tell `awk' how to do
  7001. + certain things.  Others are set automatically by `awk', so that they
  7002. + carry information from the internal workings of `awk' to your program.
  7003. +    This chapter documents all the built-in variables of `gawk'.  Most
  7004. + of them are also documented in the chapters where their areas of
  7005. + activity are described.
  7006. + * Menu:
  7007. + * User-modified::               Built-in variables that you change
  7008. +                                 to control `awk'.
  7009. + * Auto-set::                    Built-in variables where `awk'
  7010. +                                 gives you information.
  7011. + 
  7012. + File: gawk.info,  Node: User-modified,  Next: Auto-set,  Prev: Built-in Variables,  Up: Built-in Variables
  7013. + Built-in Variables that Control `awk'
  7014. + =====================================
  7015. +    This is a list of the variables which you can change to control how
  7016. + `awk' does certain things.
  7017. + `CONVFMT'
  7018. +      This string is used by `awk' to control conversion of numbers to
  7019. +      strings (*note Conversion of Strings and Numbers: Conversion.).
  7020. +      It works by being passed, in effect, as the first argument to the
  7021. +      `sprintf' function.  Its default value is `"%.6g"'.  `CONVFMT' was
  7022. +      introduced by the POSIX standard.
  7023. + `FIELDWIDTHS'
  7024. +      This is a space separated list of columns that tells `gawk' how to
  7025. +      manage input with fixed, columnar boundaries.  It is an
  7026. +      experimental feature that is still evolving.  Assigning to
  7027. +      `FIELDWIDTHS' overrides the use of `FS' for field splitting.
  7028. +      *Note Reading Fixed-width Data: Constant Size, for more
  7029. +      information.
  7030. +      If `gawk' is in compatibility mode (*note Invoking `awk': Command
  7031. +      Line.), then `FIELDWIDTHS' has no special meaning, and field
  7032. +      splitting operations are done based exclusively on the value of
  7033. +      `FS'.
  7034. + `FS'
  7035. +      `FS' is the input field separator (*note Specifying how Fields are
  7036. +      Separated: Field Separators.).  The value is a single-character
  7037. +      string or a multi-character regular expression that matches the
  7038. +      separations between fields in an input record.
  7039. +      The default value is `" "', a string consisting of a single space.
  7040. +      As a special exception, this value actually means that any
  7041. +      sequence of spaces and tabs is a single separator.  It also causes
  7042. +      spaces and tabs at the beginning or end of a line to be ignored.
  7043. +      You can set the value of `FS' on the command line using the `-F'
  7044. +      option:
  7045. +           awk -F, 'PROGRAM' INPUT-FILES
  7046. +      If `gawk' is using `FIELDWIDTHS' for field-splitting, assigning a
  7047. +      value to `FS' will cause `gawk' to return to the normal,
  7048. +      regexp-based, field splitting.
  7049. + `IGNORECASE'
  7050. +      If `IGNORECASE' is nonzero, then *all* regular expression matching
  7051. +      is done in a case-independent fashion.  In particular, regexp
  7052. +      matching with `~' and `!~', and the `gsub' `index', `match',
  7053. +      `split' and `sub' functions all ignore case when doing their
  7054. +      particular regexp operations.  *Note:* since field splitting with
  7055. +      the value of the `FS' variable is also a regular expression
  7056. +      operation, that too is done with case ignored.  *Note
  7057. +      Case-sensitivity in Matching: Case-sensitivity.
  7058. +      If `gawk' is in compatibility mode (*note Invoking `awk': Command
  7059. +      Line.), then `IGNORECASE' has no special meaning, and regexp
  7060. +      operations are always case-sensitive.
  7061. + `OFMT'
  7062. +      This string is used by `awk' to control conversion of numbers to
  7063. +      strings (*note Conversion of Strings and Numbers: Conversion.) for
  7064. +      printing with the `print' statement.  It works by being passed, in
  7065. +      effect, as the first argument to the `sprintf' function.  Its
  7066. +      default value is `"%.6g"'.  Earlier versions of `awk' also used
  7067. +      `OFMT' to specify the format for converting numbers to strings in
  7068. +      general expressions; this has been taken over by `CONVFMT'.
  7069. + `OFS'
  7070. +      This is the output field separator (*note Output Separators::.).
  7071. +      It is output between the fields output by a `print' statement.  Its
  7072. +      default value is `" "', a string consisting of a single space.
  7073. + `ORS'
  7074. +      This is the output record separator.  It is output at the end of
  7075. +      every `print' statement.  Its default value is a string containing
  7076. +      a single newline character, which could be written as `"\n"'.
  7077. +      (*Note Output Separators::.)
  7078. + `RS'
  7079. +      This is `awk''s input record separator.  Its default value is a
  7080. +      string containing a single newline character, which means that an
  7081. +      input record consists of a single line of text.  (*Note How Input
  7082. +      is Split into Records: Records.)
  7083. + `SUBSEP'
  7084. +      `SUBSEP' is the subscript separator.  It has the default value of
  7085. +      `"\034"', and is used to separate the parts of the name of a
  7086. +      multi-dimensional array.  Thus, if you access `foo[12,3]', it
  7087. +      really accesses `foo["12\0343"]' (*note Multi-dimensional Arrays:
  7088. +      Multi-dimensional.).
  7089. + 
  7090. + File: gawk.info,  Node: Auto-set,  Prev: User-modified,  Up: Built-in Variables
  7091. + Built-in Variables that Convey Information
  7092. + ==========================================
  7093. +    This is a list of the variables that are set automatically by `awk'
  7094. + on certain occasions so as to provide information to your program.
  7095. + `ARGC'
  7096. + `ARGV'
  7097. +      The command-line arguments available to `awk' programs are stored
  7098. +      in an array called `ARGV'.  `ARGC' is the number of command-line
  7099. +      arguments present.  *Note Invoking `awk': Command Line.  `ARGV' is
  7100. +      indexed from zero to `ARGC - 1'.  For example:
  7101. +           awk 'BEGIN {
  7102. +                  for (i = 0; i < ARGC; i++)
  7103. +                      print ARGV[i]
  7104. +                }' inventory-shipped BBS-list
  7105. +      In this example, `ARGV[0]' contains `"awk"', `ARGV[1]' contains
  7106. +      `"inventory-shipped"', and `ARGV[2]' contains `"BBS-list"'.  The
  7107. +      value of `ARGC' is 3, one more than the index of the last element
  7108. +      in `ARGV' since the elements are numbered from zero.
  7109. +      The names `ARGC' and `ARGV', as well the convention of indexing
  7110. +      the array from 0 to `ARGC - 1', are derived from the C language's
  7111. +      method of accessing command line arguments.
  7112. +      Notice that the `awk' program is not entered in `ARGV'.  The other
  7113. +      special command line options, with their arguments, are also not
  7114. +      entered.  But variable assignments on the command line *are*
  7115. +      treated as arguments, and do show up in the `ARGV' array.
  7116. +      Your program can alter `ARGC' and the elements of `ARGV'.  Each
  7117. +      time `awk' reaches the end of an input file, it uses the next
  7118. +      element of `ARGV' as the name of the next input file.  By storing a
  7119. +      different string there, your program can change which files are
  7120. +      read.  You can use `"-"' to represent the standard input.  By
  7121. +      storing additional elements and incrementing `ARGC' you can cause
  7122. +      additional files to be read.
  7123. +      If you decrease the value of `ARGC', that eliminates input files
  7124. +      from the end of the list.  By recording the old value of `ARGC'
  7125. +      elsewhere, your program can treat the eliminated arguments as
  7126. +      something other than file names.
  7127. +      To eliminate a file from the middle of the list, store the null
  7128. +      string (`""') into `ARGV' in place of the file's name.  As a
  7129. +      special feature, `awk' ignores file names that have been replaced
  7130. +      with the null string.
  7131. + `ARGIND'
  7132. +      The index in `ARGV' of the current file being processed.  Every
  7133. +      time `gawk' opens a new data file for processing, it sets `ARGIND'
  7134. +      to the index in `ARGV' of the file name.  Thus, the condition
  7135. +      `FILENAME == ARGV[ARGIND]' is always true.
  7136. +      This variable is useful in file processing; it allows you to tell
  7137. +      how far along you are in the list of data files, and to
  7138. +      distinguish between multiple successive instances of the same
  7139. +      filename on the command line.
  7140. +      While you can change the value of `ARGIND' within your `awk'
  7141. +      program, `gawk' will automatically set it to a new value when the
  7142. +      next file is opened.
  7143. +      This variable is a `gawk' extension; in other `awk' implementations
  7144. +      it is not special.
  7145. + `ENVIRON'
  7146. +      This is an array that contains the values of the environment.  The
  7147. +      array indices are the environment variable names; the values are
  7148. +      the values of the particular environment variables.  For example,
  7149. +      `ENVIRON["HOME"]' might be `/u/close'.  Changing this array does
  7150. +      not affect the environment passed on to any programs that `awk'
  7151. +      may spawn via redirection or the `system' function.  (In a future
  7152. +      version of `gawk', it may do so.)
  7153. +      Some operating systems may not have environment variables.  On
  7154. +      such systems, the array `ENVIRON' is empty.
  7155. + `ERRNO'
  7156. +      If a system error occurs either doing a redirection for `getline',
  7157. +      during a read for `getline', or during a `close' operation, then
  7158. +      `ERRNO' will contain a string describing the error.
  7159. +      This variable is a `gawk' extension; in other `awk' implementations
  7160. +      it is not special.
  7161. + `FILENAME'
  7162. +      This is the name of the file that `awk' is currently reading.  If
  7163. +      `awk' is reading from the standard input (in other words, there
  7164. +      are no files listed on the command line), `FILENAME' is set to
  7165. +      `"-"'.  `FILENAME' is changed each time a new file is read (*note
  7166. +      Reading Input Files: Reading Files.).
  7167. + `FNR'
  7168. +      `FNR' is the current record number in the current file.  `FNR' is
  7169. +      incremented each time a new record is read (*note Explicit Input
  7170. +      with `getline': Getline.).  It is reinitialized to 0 each time a
  7171. +      new input file is started.
  7172. + `NF'
  7173. +      `NF' is the number of fields in the current input record.  `NF' is
  7174. +      set each time a new record is read, when a new field is created,
  7175. +      or when `$0' changes (*note Examining Fields: Fields.).
  7176. + `NR'
  7177. +      This is the number of input records `awk' has processed since the
  7178. +      beginning of the program's execution.  (*note How Input is Split
  7179. +      into Records: Records.).  `NR' is set each time a new record is
  7180. +      read.
  7181. + `RLENGTH'
  7182. +      `RLENGTH' is the length of the substring matched by the `match'
  7183. +      function (*note Built-in Functions for String Manipulation: String
  7184. +      Functions.).  `RLENGTH' is set by invoking the `match' function.
  7185. +      Its value is the length of the matched string, or -1 if no match
  7186. +      was found.
  7187. + `RSTART'
  7188. +      `RSTART' is the start-index in characters of the substring matched
  7189. +      by the `match' function (*note Built-in Functions for String
  7190. +      Manipulation: String Functions.).  `RSTART' is set by invoking the
  7191. +      `match' function.  Its value is the position of the string where
  7192. +      the matched substring starts, or 0 if no match was found.
  7193. + 
  7194. + File: gawk.info,  Node: Command Line,  Next: Language History,  Prev: Built-in Variables,  Up: Top
  7195. + Invoking `awk'
  7196. + **************
  7197. +    There are two ways to run `awk': with an explicit program, or with
  7198. + one or more program files.  Here are templates for both of them; items
  7199. + enclosed in `[...]' in these templates are optional.
  7200. +    Besides traditional one-letter POSIX-style options, `gawk' also
  7201. + supports GNU long named options.
  7202. +      awk [POSIX OR GNU STYLE OPTIONS] -f progfile [`--'] FILE ...
  7203. +      awk [POSIX OR GNU STYLE OPTIONS] [`--'] 'PROGRAM' FILE ...
  7204. + * Menu:
  7205. + * Options::                     Command line options and their meanings.
  7206. + * Other Arguments::             Input file names and variable assignments.
  7207. + * AWKPATH Variable::            Searching directories for `awk' programs.
  7208. + * Obsolete::                    Obsolete Options and/or features.
  7209. + * Undocumented::                Undocumented Options and Features.
  7210. + 
  7211. + File: gawk.info,  Node: Options,  Next: Other Arguments,  Prev: Command Line,  Up: Command Line
  7212. + Command Line Options
  7213. + ====================
  7214. +    Options begin with a minus sign, and consist of a single character.
  7215. + GNU style long named options consist of two minus signs and a keyword
  7216. + that can be abbreviated if the abbreviation allows the option to be
  7217. + uniquely identified.  If the option takes an argument, then the keyword
  7218. + is immediately followed by an equals sign (`=') and the argument's
  7219. + value.  For brevity, the discussion below only refers to the
  7220. + traditional short options; however the long and short options are
  7221. + interchangeable in all contexts.
  7222. +    Each long named option for `gawk' has a corresponding POSIX-style
  7223. + option.  The options and their meanings are as follows:
  7224. + `-F FS'
  7225. + `--field-separator=FS'
  7226. +      Sets the `FS' variable to FS (*note Specifying how Fields are
  7227. +      Separated: Field Separators.).
  7228. + `-f SOURCE-FILE'
  7229. + `--file=SOURCE-FILE'
  7230. +      Indicates that the `awk' program is to be found in SOURCE-FILE
  7231. +      instead of in the first non-option argument.
  7232. + `-v VAR=VAL'
  7233. + `--assign=VAR=VAL'
  7234. +      Sets the variable VAR to the value VAL *before* execution of the
  7235. +      program begins.  Such variable values are available inside the
  7236. +      `BEGIN' rule (see below for a fuller explanation).
  7237. +      The `-v' option can only set one variable, but you can use it more
  7238. +      than once, setting another variable each time, like this:
  7239. +      `-v foo=1 -v bar=2'.
  7240. + `-W GAWK-OPT'
  7241. +      Following the POSIX standard, options that are implementation
  7242. +      specific are supplied as arguments to the `-W' option.  With
  7243. +      `gawk', these arguments may be separated by commas, or quoted and
  7244. +      separated by whitespace.  Case is ignored when processing these
  7245. +      options.  These options also have corresponding GNU style long
  7246. +      named options.  The following `gawk'-specific options are
  7247. +      available:
  7248. +     `-W compat'
  7249. +     `--compat'
  7250. +           Specifies "compatibility mode", in which the GNU extensions in
  7251. +           `gawk' are disabled, so that `gawk' behaves just like Unix
  7252. +           `awk'.  *Note Extensions in `gawk' not in POSIX `awk':
  7253. +           POSIX/GNU, which summarizes the extensions.  Also see *Note
  7254. +           Downward Compatibility and Debugging: Compatibility Mode.
  7255. +     `-W copyleft'
  7256. +     `-W copyright'
  7257. +     `--copyleft'
  7258. +     `--copyright'
  7259. +           Print the short version of the General Public License.  This
  7260. +           option may disappear in a future version of `gawk'.
  7261. +     `-W help'
  7262. +     `-W usage'
  7263. +     `--help'
  7264. +     `--usage'
  7265. +           Print a "usage" message summarizing the short and long style
  7266. +           options that `gawk' accepts, and then exit.
  7267. +     `-W lint'
  7268. +     `--lint'
  7269. +           Provide warnings about constructs that are dubious or
  7270. +           non-portable to other `awk' implementations.  Some warnings
  7271. +           are issued when `gawk' first reads your program.  Others are
  7272. +           issued at run-time, as your program executes.
  7273. +     `-W posix'
  7274. +     `--posix'
  7275. +           Operate in strict POSIX mode.  This disables all `gawk'
  7276. +           extensions (just like `-W compat'), and adds the following
  7277. +           additional restrictions:
  7278. +              * `\x' escape sequences are not recognized (*note Constant
  7279. +                Expressions: Constants.).
  7280. +              * The synonym `func' for the keyword `function' is not
  7281. +                recognized (*note Syntax of Function Definitions:
  7282. +                Definition Syntax.).
  7283. +              * The operators `**' and `**=' cannot be used in place of
  7284. +                `^' and `^=' (*note Arithmetic Operators: Arithmetic
  7285. +                Ops., and also *note Assignment Expressions: Assignment
  7286. +                Ops.).
  7287. +              * Specifying `-Ft' on the command line does not set the
  7288. +                value of `FS' to be a single tab character (*note
  7289. +                Specifying how Fields are Separated: Field Separators.).
  7290. +           Although you can supply both `-W compat' and `-W posix' on the
  7291. +           command line, `-W posix' will take precedence.
  7292. +     `-W source=PROGRAM-TEXT'
  7293. +     `--source=PROGRAM-TEXT'
  7294. +           Program source code is taken from the PROGRAM-TEXT.  This
  7295. +           option allows you to mix `awk' source code in files with
  7296. +           program source code that you would enter on the command line.
  7297. +           This is particularly useful when you have library functions
  7298. +           that you wish to use from your command line programs (*note
  7299. +           The `AWKPATH' Environment Variable: AWKPATH Variable.).
  7300. +     `-W version'
  7301. +     `--version'
  7302. +           Prints version information for this particular copy of `gawk'.
  7303. +           This is so you can determine if your copy of `gawk' is up to
  7304. +           date with respect to whatever the Free Software Foundation is
  7305. +           currently distributing.  This option may disappear in a
  7306. +           future version of `gawk'.
  7307. + `--'
  7308. +      Signals the end of the command line options.  The following
  7309. +      arguments are not treated as options even if they begin with `-'.
  7310. +      This interpretation of `--' follows the POSIX argument parsing
  7311. +      conventions.
  7312. +      This is useful if you have file names that start with `-', or in
  7313. +      shell scripts, if you have file names that will be specified by
  7314. +      the user which could start with `-'.
  7315. +    Any other options are flagged as invalid with a warning message, but
  7316. + are otherwise ignored.
  7317. +    In compatibility mode, as a special case, if the value of FS supplied
  7318. + to the `-F' option is `t', then `FS' is set to the tab character
  7319. + (`"\t"').  This is only true for `-W compat', and not for `-W posix'
  7320. + (*note Specifying how Fields are Separated: Field Separators.).
  7321. +    If the `-f' option is *not* used, then the first non-option command
  7322. + line argument is expected to be the program text.
  7323. +    The `-f' option may be used more than once on the command line.  If
  7324. + it is, `awk' reads its program source from all of the named files, as
  7325. + if they had been concatenated together into one big file.  This is
  7326. + useful for creating libraries of `awk' functions.  Useful functions can
  7327. + be written once, and then retrieved from a standard place, instead of
  7328. + having to be included into each individual program.  You can still type
  7329. + in a program at the terminal and use library functions, by specifying
  7330. + `-f /dev/tty'.  `awk' will read a file from the terminal to use as part
  7331. + of the `awk' program.  After typing your program, type `Control-d' (the
  7332. + end-of-file character) to terminate it.  (You may also use `-f -' to
  7333. + read program source from the standard input, but then you will not be
  7334. + able to also use the standard input as a source of data.)
  7335. +    Because it is clumsy using the standard `awk' mechanisms to mix
  7336. + source file and command line `awk' programs, `gawk' provides the
  7337. + `--source' option.  This does not require you to pre-empt the standard
  7338. + input for your source code, and allows you to easily mix command line
  7339. + and library source code (*note The `AWKPATH' Environment Variable:
  7340. + AWKPATH Variable.).
  7341. +    If no `-f' or `--source' option is specified, then `gawk' will use
  7342. + the first non-option command line argument as the text of the program
  7343. + source code.
  7344. + 
  7345. + File: gawk.info,  Node: Other Arguments,  Next: AWKPATH Variable,  Prev: Options,  Up: Command Line
  7346. + Other Command Line Arguments
  7347. + ============================
  7348. +    Any additional arguments on the command line are normally treated as
  7349. + input files to be processed in the order specified.  However, an
  7350. + argument that has the form `VAR=VALUE', means to assign the value VALUE
  7351. + to the variable VAR--it does not specify a file at all.
  7352. +    All these arguments are made available to your `awk' program in the
  7353. + `ARGV' array (*note Built-in Variables::.).  Command line options and
  7354. + the program text (if present) are omitted from the `ARGV' array.  All
  7355. + other arguments, including variable assignments, are included.
  7356. +    The distinction between file name arguments and variable-assignment
  7357. + arguments is made when `awk' is about to open the next input file.  At
  7358. + that point in execution, it checks the "file name" to see whether it is
  7359. + really a variable assignment; if so, `awk' sets the variable instead of
  7360. + reading a file.
  7361. +    Therefore, the variables actually receive the specified values after
  7362. + all previously specified files have been read.  In particular, the
  7363. + values of variables assigned in this fashion are *not* available inside
  7364. + a `BEGIN' rule (*note `BEGIN' and `END' Special Patterns: BEGIN/END.),
  7365. + since such rules are run before `awk' begins scanning the argument list.
  7366. + The values given on the command line are processed for escape sequences
  7367. + (*note Constant Expressions: Constants.).
  7368. +    In some earlier implementations of `awk', when a variable assignment
  7369. + occurred before any file names, the assignment would happen *before*
  7370. + the `BEGIN' rule was executed.  Some applications came to depend upon
  7371. + this "feature."  When `awk' was changed to be more consistent, the `-v'
  7372. + option was added to accommodate applications that depended upon this
  7373. + old behavior.
  7374. +    The variable assignment feature is most useful for assigning to
  7375. + variables such as `RS', `OFS', and `ORS', which control input and
  7376. + output formats, before scanning the data files.  It is also useful for
  7377. + controlling state if multiple passes are needed over a data file.  For
  7378. + example:
  7379. +      awk 'pass == 1  { PASS 1 STUFF }
  7380. +           pass == 2  { PASS 2 STUFF }' pass=1 datafile pass=2 datafile
  7381. +    Given the variable assignment feature, the `-F' option is not
  7382. + strictly necessary.  It remains for historical compatibility.
  7383. + 
  7384. + File: gawk.info,  Node: AWKPATH Variable,  Next: Obsolete,  Prev: Other Arguments,  Up: Command Line
  7385. + The `AWKPATH' Environment Variable
  7386. + ==================================
  7387. +    The previous section described how `awk' program files can be named
  7388. + on the command line with the `-f' option.  In some `awk'
  7389. + implementations, you must supply a precise path name for each program
  7390. + file, unless the file is in the current directory.
  7391. +    But in `gawk', if the file name supplied in the `-f' option does not
  7392. + contain a `/', then `gawk' searches a list of directories (called the
  7393. + "search path"), one by one, looking for a file with the specified name.
  7394. +    The search path is actually a string consisting of directory names
  7395. + separated by colons.  `gawk' gets its search path from the `AWKPATH'
  7396. + environment variable.  If that variable does not exist, `gawk' uses the
  7397. + default path, which is `.:/local/lib/awk:/gnu/lib/awk'.  (Programs
  7398. + written by system administrators should use an `AWKPATH' variable that
  7399. + does not include the current directory, `.'.)
  7400. +    The search path feature is particularly useful for building up
  7401. + libraries of useful `awk' functions.  The library files can be placed
  7402. + in a standard directory that is in the default path, and then specified
  7403. + on the command line with a short file name.  Otherwise, the full file
  7404. + name would have to be typed for each file.
  7405. +    By combining the `--source' and `-f' options, your command line
  7406. + `awk' programs can use facilities in `awk' library files.
  7407. +    Path searching is not done if `gawk' is in compatibility mode.  This
  7408. + is true for both `-W compat' and `-W posix'.  *Note Command Line
  7409. + Options: Options.
  7410. +    *Note:* if you want files in the current directory to be found, you
  7411. + must include the current directory in the path, either by writing `.'
  7412. + as an entry in the path, or by writing a null entry in the path.  (A
  7413. + null entry is indicated by starting or ending the path with a colon, or
  7414. + by placing two colons next to each other (`::').)  If the current
  7415. + directory is not included in the path, then files cannot be found in
  7416. + the current directory.  This path search mechanism is identical to the
  7417. + shell's.
  7418. + 
  7419. + File: gawk.info,  Node: Obsolete,  Next: Undocumented,  Prev: AWKPATH Variable,  Up: Command Line
  7420. + Obsolete Options and/or Features
  7421. + ================================
  7422. +    This section describes features and/or command line options from the
  7423. + previous release of `gawk' that are either not available in the current
  7424. + version, or that are still supported but deprecated (meaning that they
  7425. + will *not* be in the next release).
  7426. +    For version 2.15 of `gawk', the following command line options from
  7427. + version 2.11.1 are no longer recognized.
  7428. + `-c'
  7429. +      Use `-W compat' instead.
  7430. + `-V'
  7431. +      Use `-W version' instead.
  7432. + `-C'
  7433. +      Use `-W copyright' instead.
  7434. + `-a'
  7435. + `-e'
  7436. +      These options produce an "unrecognized option" error message but
  7437. +      have no effect on the execution of `gawk'.  The POSIX standard now
  7438. +      specifies traditional `awk' regular expressions for the `awk'
  7439. +      utility.
  7440. +    The public-domain version of `strftime' that is distributed with
  7441. + `gawk' changed for the 2.14 release.  The `%V' conversion specifier
  7442. + that used to generate the date in VMS format was changed to `%v'.  This
  7443. + is because the POSIX standard for the `date' utility now specifies a
  7444. + `%V' conversion specifier.  *Note Functions for Dealing with Time
  7445. + Stamps: Time Functions, for details.
  7446. + 
  7447. + File: gawk.info,  Node: Undocumented,  Prev: Obsolete,  Up: Command Line
  7448. + Undocumented Options and Features
  7449. + =================================
  7450. +    This section intentionally left blank.
  7451. + 
  7452. + File: gawk.info,  Node: Language History,  Next: Installation,  Prev: Command Line,  Up: Top
  7453. + The Evolution of the `awk' Language
  7454. + ***********************************
  7455. +    This manual describes the GNU implementation of `awk', which is
  7456. + patterned after the POSIX specification.  Many `awk' users are only
  7457. + familiar with the original `awk' implementation in Version 7 Unix,
  7458. + which is also the basis for the version in Berkeley Unix (through
  7459. + 4.3-Reno).  This chapter briefly describes the evolution of the `awk'
  7460. + language.
  7461. + * Menu:
  7462. + * V7/S5R3.1::                   The major changes between V7 and
  7463. +                                 System V Release 3.1.
  7464. + * S5R4::                        Minor changes between System V
  7465. +                                 Releases 3.1 and 4.
  7466. + * POSIX::                       New features from the POSIX standard.
  7467. + * POSIX/GNU::                   The extensions in `gawk'
  7468. +                                 not in POSIX `awk'.
  7469. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-7 gawk-2.15.5/gawk.info-7
  7470. *** /src/baseline/gawk-2.15.5/gawk.info-7    Thu Jan  1 00:00:00 1970
  7471. --- gawk-2.15.5/gawk.info-7    Sun Jun 12 22:28:55 1994
  7472. ***************
  7473. *** 0 ****
  7474. --- 1,1265 ----
  7475. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  7476. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  7477. +    This file documents `awk', a program that you can use to select
  7478. + particular records in a file and perform operations upon them.
  7479. +    This is Edition 0.15 of `The GAWK Manual',
  7480. + for the 2.15 version of the GNU implementation
  7481. + of AWK.
  7482. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  7483. +    Permission is granted to make and distribute verbatim copies of this
  7484. + manual provided the copyright notice and this permission notice are
  7485. + preserved on all copies.
  7486. +    Permission is granted to copy and distribute modified versions of
  7487. + this manual under the conditions for verbatim copying, provided that
  7488. + the entire resulting derived work is distributed under the terms of a
  7489. + permission notice identical to this one.
  7490. +    Permission is granted to copy and distribute translations of this
  7491. + manual into another language, under the above conditions for modified
  7492. + versions, except that this permission notice may be stated in a
  7493. + translation approved by the Foundation.
  7494. + 
  7495. + File: gawk.info,  Node: V7/S5R3.1,  Next: S5R4,  Prev: Language History,  Up: Language History
  7496. + Major Changes between V7 and S5R3.1
  7497. + ===================================
  7498. +    The `awk' language evolved considerably between the release of
  7499. + Version 7 Unix (1978) and the new version first made widely available in
  7500. + System V Release 3.1 (1987).  This section summarizes the changes, with
  7501. + cross-references to further details.
  7502. +    * The requirement for `;' to separate rules on a line (*note `awk'
  7503. +      Statements versus Lines: Statements/Lines.).
  7504. +    * User-defined functions, and the `return' statement (*note
  7505. +      User-defined Functions: User-defined.).
  7506. +    * The `delete' statement (*note The `delete' Statement: Delete.).
  7507. +    * The `do'-`while' statement (*note The `do'-`while' Statement: Do
  7508. +      Statement.).
  7509. +    * The built-in functions `atan2', `cos', `sin', `rand' and `srand'
  7510. +      (*note Numeric Built-in Functions: Numeric Functions.).
  7511. +    * The built-in functions `gsub', `sub', and `match' (*note Built-in
  7512. +      Functions for String Manipulation: String Functions.).
  7513. +    * The built-in functions `close', which closes an open file, and
  7514. +      `system', which allows the user to execute operating system
  7515. +      commands (*note Built-in Functions for Input/Output: I/O
  7516. +      Functions.).
  7517. +    * The `ARGC', `ARGV', `FNR', `RLENGTH', `RSTART', and `SUBSEP'
  7518. +      built-in variables (*note Built-in Variables::.).
  7519. +    * The conditional expression using the operators `?' and `:' (*note
  7520. +      Conditional Expressions: Conditional Exp.).
  7521. +    * The exponentiation operator `^' (*note Arithmetic Operators:
  7522. +      Arithmetic Ops.) and its assignment operator form `^=' (*note
  7523. +      Assignment Expressions: Assignment Ops.).
  7524. +    * C-compatible operator precedence, which breaks some old `awk'
  7525. +      programs (*note Operator Precedence (How Operators Nest):
  7526. +      Precedence.).
  7527. +    * Regexps as the value of `FS' (*note Specifying how Fields are
  7528. +      Separated: Field Separators.), and as the third argument to the
  7529. +      `split' function (*note Built-in Functions for String
  7530. +      Manipulation: String Functions.).
  7531. +    * Dynamic regexps as operands of the `~' and `!~' operators (*note
  7532. +      How to Use Regular Expressions: Regexp Usage.).
  7533. +    * Escape sequences (*note Constant Expressions: Constants.) in
  7534. +      regexps.
  7535. +    * The escape sequences `\b', `\f', and `\r' (*note Constant
  7536. +      Expressions: Constants.).
  7537. +    * Redirection of input for the `getline' function (*note Explicit
  7538. +      Input with `getline': Getline.).
  7539. +    * Multiple `BEGIN' and `END' rules (*note `BEGIN' and `END' Special
  7540. +      Patterns: BEGIN/END.).
  7541. +    * Simulated multi-dimensional arrays (*note Multi-dimensional
  7542. +      Arrays: Multi-dimensional.).
  7543. + 
  7544. + File: gawk.info,  Node: S5R4,  Next: POSIX,  Prev: V7/S5R3.1,  Up: Language History
  7545. + Changes between S5R3.1 and S5R4
  7546. + ===============================
  7547. +    The System V Release 4 version of Unix `awk' added these features
  7548. + (some of which originated in `gawk'):
  7549. +    * The `ENVIRON' variable (*note Built-in Variables::.).
  7550. +    * Multiple `-f' options on the command line (*note Invoking `awk':
  7551. +      Command Line.).
  7552. +    * The `-v' option for assigning variables before program execution
  7553. +      begins (*note Invoking `awk': Command Line.).
  7554. +    * The `--' option for terminating command line options.
  7555. +    * The `\a', `\v', and `\x' escape sequences (*note Constant
  7556. +      Expressions: Constants.).
  7557. +    * A defined return value for the `srand' built-in function (*note
  7558. +      Numeric Built-in Functions: Numeric Functions.).
  7559. +    * The `toupper' and `tolower' built-in string functions for case
  7560. +      translation (*note Built-in Functions for String Manipulation:
  7561. +      String Functions.).
  7562. +    * A cleaner specification for the `%c' format-control letter in the
  7563. +      `printf' function (*note Using `printf' Statements for Fancier
  7564. +      Printing: Printf.).
  7565. +    * The ability to dynamically pass the field width and precision
  7566. +      (`"%*.*d"') in the argument list of the `printf' function (*note
  7567. +      Using `printf' Statements for Fancier Printing: Printf.).
  7568. +    * The use of constant regexps such as `/foo/' as expressions, where
  7569. +      they are equivalent to use of the matching operator, as in `$0 ~
  7570. +      /foo/' (*note Constant Expressions: Constants.).
  7571. + 
  7572. + File: gawk.info,  Node: POSIX,  Next: POSIX/GNU,  Prev: S5R4,  Up: Language History
  7573. + Changes between S5R4 and POSIX `awk'
  7574. + ====================================
  7575. +    The POSIX Command Language and Utilities standard for `awk'
  7576. + introduced the following changes into the language:
  7577. +    * The use of `-W' for implementation-specific options.
  7578. +    * The use of `CONVFMT' for controlling the conversion of numbers to
  7579. +      strings (*note Conversion of Strings and Numbers: Conversion.).
  7580. +    * The concept of a numeric string, and tighter comparison rules to go
  7581. +      with it (*note Comparison Expressions: Comparison Ops.).
  7582. +    * More complete documentation of many of the previously undocumented
  7583. +      features of the language.
  7584. + 
  7585. + File: gawk.info,  Node: POSIX/GNU,  Prev: POSIX,  Up: Language History
  7586. + Extensions in `gawk' not in POSIX `awk'
  7587. + =======================================
  7588. +    The GNU implementation, `gawk', adds these features:
  7589. +    * The `AWKPATH' environment variable for specifying a path search for
  7590. +      the `-f' command line option (*note Invoking `awk': Command Line.).
  7591. +    * The various `gawk' specific features available via the `-W'
  7592. +      command line option (*note Invoking `awk': Command Line.).
  7593. +    * The `ARGIND' variable, that tracks the movement of `FILENAME'
  7594. +      through `ARGV'.  (*note Built-in Variables::.).
  7595. +    * The `ERRNO' variable, that contains the system error message when
  7596. +      `getline' returns -1, or when `close' fails.  (*note Built-in
  7597. +      Variables::.).
  7598. +    * The `IGNORECASE' variable and its effects (*note Case-sensitivity
  7599. +      in Matching: Case-sensitivity.).
  7600. +    * The `FIELDWIDTHS' variable and its effects (*note Reading
  7601. +      Fixed-width Data: Constant Size.).
  7602. +    * The `next file' statement for skipping to the next data file
  7603. +      (*note The `next file' Statement: Next File Statement.).
  7604. +    * The `systime' and `strftime' built-in functions for obtaining and
  7605. +      printing time stamps (*note Functions for Dealing with Time
  7606. +      Stamps: Time Functions.).
  7607. +    * The `/dev/stdin', `/dev/stdout', `/dev/stderr', and `/dev/fd/N'
  7608. +      file name interpretation (*note Standard I/O Streams: Special
  7609. +      Files.).
  7610. +    * The `-W compat' option to turn off these extensions (*note
  7611. +      Invoking `awk': Command Line.).
  7612. +    * The `-W posix' option for full POSIX compliance (*note Invoking
  7613. +      `awk': Command Line.).
  7614. + 
  7615. + File: gawk.info,  Node: Installation,  Next: Gawk Summary,  Prev: Language History,  Up: Top
  7616. + Installing `gawk'
  7617. + *****************
  7618. +    This chapter provides instructions for installing `gawk' on the
  7619. + various platforms that are supported by the developers.  The primary
  7620. + developers support Unix (and one day, GNU), while the other ports were
  7621. + contributed.  The file `ACKNOWLEDGMENT' in the `gawk' distribution
  7622. + lists the electronic mail addresses of the people who did the
  7623. + respective ports.
  7624. + * Menu:
  7625. + * Gawk Distribution::           What is in the `gawk' distribution.
  7626. + * Unix Installation::           Installing `gawk' under various versions
  7627. +                                 of Unix.
  7628. + * VMS Installation::            Installing `gawk' on VMS.
  7629. + * MS-DOS Installation::         Installing `gawk' on MS-DOS.
  7630. + * Atari Installation::          Installing `gawk' on the Atari ST.
  7631. + 
  7632. + File: gawk.info,  Node: Gawk Distribution,  Next: Unix Installation,  Prev: Installation,  Up: Installation
  7633. + The `gawk' Distribution
  7634. + =======================
  7635. +    This section first describes how to get and extract the `gawk'
  7636. + distribution, and then discusses what is in the various files and
  7637. + subdirectories.
  7638. + * Menu:
  7639. + * Extracting::                  How to get and extract the distribution.
  7640. + * Distribution contents::       What is in the distribution.
  7641. + 
  7642. + File: gawk.info,  Node: Extracting,  Next: Distribution contents,  Prev: Gawk Distribution,  Up: Gawk Distribution
  7643. + Getting the `gawk' Distribution
  7644. + -------------------------------
  7645. +    `gawk' is distributed as a `tar' file compressed with the GNU Zip
  7646. + program, `gzip'.  You can get it via anonymous `ftp' to the Internet
  7647. + host `prep.ai.mit.edu'.  Like all GNU software, it will be archived at
  7648. + other well known systems, from which it will be possible to use some
  7649. + sort of anonymous `uucp' to obtain the distribution as well.  You can
  7650. + also order `gawk' on tape or CD-ROM directly from the Free Software
  7651. + Foundation.  (The address is on the copyright page.) Doing so directly
  7652. + contributes to the support of the foundation and to the production of
  7653. + more free software.
  7654. +    Once you have the distribution (for example, `gawk-2.15.0.tar.z'),
  7655. + first use `gzip' to expand the file, and then use `tar' to extract it.
  7656. + You can use the following pipeline to produce the `gawk' distribution:
  7657. +      # Under System V, add 'o' to the tar flags
  7658. +      gzip -d -c gawk-2.15.0.tar.z | tar -xvpf -
  7659. + This will create a directory named `gawk-2.15' in the current directory.
  7660. +    The distribution file name is of the form `gawk-2.15.N.tar.Z'.  The
  7661. + N represents a "patchlevel", meaning that minor bugs have been fixed in
  7662. + the major release.  The current patchlevel is 0, but when retrieving
  7663. + distributions, you should get the version with the highest patchlevel.
  7664. +    If you are not on a Unix system, you will need to make other
  7665. + arrangements for getting and extracting the `gawk' distribution.  You
  7666. + should consult a local expert.
  7667. + 
  7668. + File: gawk.info,  Node: Distribution contents,  Prev: Extracting,  Up: Gawk Distribution
  7669. + Contents of the `gawk' Distribution
  7670. + -----------------------------------
  7671. +    `gawk' has a number of C source files, documentation files,
  7672. + subdirectories and files related to the configuration process (*note
  7673. + Compiling and Installing `gawk' on Unix: Unix Installation.), and
  7674. + several subdirectories related to different, non-Unix, operating
  7675. + systems.
  7676. + various `.c', `.y', and `.h' files
  7677. +      The C and YACC source files are the actual `gawk' source code.
  7678. + `README'
  7679. + `README.VMS'
  7680. + `README.dos'
  7681. + `README.rs6000'
  7682. + `README.ultrix'
  7683. +      Descriptive files: `README' for `gawk' under Unix, and the rest
  7684. +      for the various hardware and software combinations.
  7685. + `PORTS'
  7686. +      A list of systems to which `gawk' has been ported, and which have
  7687. +      successfully run the test suite.
  7688. + `ACKNOWLEDGMENT'
  7689. +      A list of the people who contributed major parts of the code or
  7690. +      documentation.
  7691. + `NEWS'
  7692. +      A list of changes to `gawk' since the last release or patch.
  7693. + `COPYING'
  7694. +      The GNU General Public License.
  7695. + `FUTURES'
  7696. +      A brief list of features and/or changes being contemplated for
  7697. +      future releases, with some indication of the time frame for the
  7698. +      feature, based on its difficulty.
  7699. + `LIMITATIONS'
  7700. +      A list of those factors that limit `gawk''s performance.  Most of
  7701. +      these depend on the hardware or operating system software, and are
  7702. +      not limits in `gawk' itself.
  7703. + `PROBLEMS'
  7704. +      A file describing known problems with the current release.
  7705. + `gawk.1'
  7706. +      The `troff' source for a manual page describing `gawk'.
  7707. + `gawk.texinfo'
  7708. +      The `texinfo' source file for this Info file.  It should be
  7709. +      processed with TeX to produce a printed manual, and with
  7710. +      `makeinfo' to produce the Info file.
  7711. + `Makefile.in'
  7712. + `config'
  7713. + `config.in'
  7714. + `configure'
  7715. + `missing'
  7716. + `mungeconf'
  7717. +      These files and subdirectories are used when configuring `gawk'
  7718. +      for various Unix systems.  They are explained in detail in *Note
  7719. +      Compiling and Installing `gawk' on Unix: Unix Installation.
  7720. + `atari'
  7721. +      Files needed for building `gawk' on an Atari ST.  *Note Installing
  7722. +      `gawk' on the Atari ST: Atari Installation, for details.
  7723. + `pc'
  7724. +      Files needed for building `gawk' under MS-DOS.  *Note Installing
  7725. +      `gawk' on MS-DOS: MS-DOS Installation, for details.
  7726. + `vms'
  7727. +      Files needed for building `gawk' under VMS.  *Note Compiling
  7728. +      Installing and Running `gawk' on VMS: VMS Installation, for
  7729. +      details.
  7730. + `test'
  7731. +      Many interesting `awk' programs, provided as a test suite for
  7732. +      `gawk'.  You can use `make test' from the top level `gawk'
  7733. +      directory to run your version of `gawk' against the test suite.
  7734. +      If `gawk' successfully passes `make test' then you can be
  7735. +      confident of a successful port.
  7736. + 
  7737. + File: gawk.info,  Node: Unix Installation,  Next: VMS Installation,  Prev: Gawk Distribution,  Up: Installation
  7738. + Compiling and Installing `gawk' on Unix
  7739. + =======================================
  7740. +    Often, you can compile and install `gawk' by typing only two
  7741. + commands.  However, if you do not use a supported system, you may need
  7742. + to configure `gawk' for your system yourself.
  7743. + * Menu:
  7744. + * Quick Installation::          Compiling `gawk' on a
  7745. +                                 supported Unix version.
  7746. + * Configuration Philosophy::    How it's all supposed to work.
  7747. + * New Configurations::          What to do if there is no supplied
  7748. +                                 configuration for your system.
  7749. + 
  7750. + File: gawk.info,  Node: Quick Installation,  Next: Configuration Philosophy,  Prev: Unix Installation,  Up: Unix Installation
  7751. + Compiling `gawk' for a Supported Unix Version
  7752. + ---------------------------------------------
  7753. +    After you have extracted the `gawk' distribution, `cd' to
  7754. + `gawk-2.15'.  Look in the `config' subdirectory for a file that matches
  7755. + your hardware/software combination.  In general, only the software is
  7756. + relevant; for example `sunos41' is used for SunOS 4.1, on both Sun 3
  7757. + and Sun 4 hardware.
  7758. +    If you find such a file, run the command:
  7759. +      # assume you have SunOS 4.1
  7760. +      ./configure sunos41
  7761. +    This produces a `Makefile' and `config.h' tailored to your system.
  7762. + You may wish to edit the `Makefile' to use a different C compiler, such
  7763. + as `gcc', the GNU C compiler, if you have it.  You may also wish to
  7764. + change the `CFLAGS' variable, which controls the command line options
  7765. + that are passed to the C compiler (such as optimization levels, or
  7766. + compiling for debugging).
  7767. +    After you have configured `Makefile' and `config.h', type:
  7768. +      make
  7769. + and shortly thereafter, you should have an executable version of `gawk'.
  7770. + That's all there is to it!
  7771. + 
  7772. + File: gawk.info,  Node: Configuration Philosophy,  Next: New Configurations,  Prev: Quick Installation,  Up: Unix Installation
  7773. + The Configuration Process
  7774. + -------------------------
  7775. +    (This section is of interest only if you know something about using
  7776. + the C language and the Unix operating system.)
  7777. +    The source code for `gawk' generally attempts to adhere to industry
  7778. + standards wherever possible.  This means that `gawk' uses library
  7779. + routines that are specified by the ANSI C standard and by the POSIX
  7780. + operating system interface standard.  When using an ANSI C compiler,
  7781. + function prototypes are provided to help improve the compile-time
  7782. + checking.
  7783. +    Many older Unix systems do not support all of either the ANSI or the
  7784. + POSIX standards.  The `missing' subdirectory in the `gawk' distribution
  7785. + contains replacement versions of those subroutines that are most likely
  7786. + to be missing.
  7787. +    The `config.h' file that is created by the `configure' program
  7788. + contains definitions that describe features of the particular operating
  7789. + system where you are attempting to compile `gawk'.  For the most part,
  7790. + it lists which standard subroutines are *not* available.  For example,
  7791. + if your system lacks the `getopt' routine, then `GETOPT_MISSING' would
  7792. + be defined.
  7793. +    `config.h' also defines constants that describe facts about your
  7794. + variant of Unix.  For example, there may not be an `st_blksize' element
  7795. + in the `stat' structure.  In this case `BLKSIZE_MISSING' would be
  7796. + defined.
  7797. +    Based on the list in `config.h' of standard subroutines that are
  7798. + missing, `missing.c' will do a `#include' of the appropriate file(s)
  7799. + from the `missing' subdirectory.
  7800. +    Conditionally compiled code in the other source files relies on the
  7801. + other definitions in the `config.h' file.
  7802. +    Besides creating `config.h', `configure' produces a `Makefile' from
  7803. + `Makefile.in'.  There are a number of lines in `Makefile.in' that are
  7804. + system or feature specific.  For example, there is line that begins
  7805. + with `##MAKE_ALLOCA_C##'.  This is normally a comment line, since it
  7806. + starts with `#'.  If a configuration file has `MAKE_ALLOCA_C' in it,
  7807. + then `configure' will delete the `##MAKE_ALLOCA_C##' from the beginning
  7808. + of the line.  This will enable the rules in the `Makefile' that use a C
  7809. + version of `alloca'.  There are several similar features that work in
  7810. + this fashion.
  7811. + 
  7812. + File: gawk.info,  Node: New Configurations,  Prev: Configuration Philosophy,  Up: Unix Installation
  7813. + Configuring `gawk' for a New System
  7814. + -----------------------------------
  7815. +    (This section is of interest only if you know something about using
  7816. + the C language and the Unix operating system, and if you have to install
  7817. + `gawk' on a system that is not supported by the `gawk' distribution.
  7818. + If you are a C or Unix novice, get help from a local expert.)
  7819. +    If you need to configure `gawk' for a Unix system that is not
  7820. + supported in the distribution, first see *Note The Configuration
  7821. + Process: Configuration Philosophy.  Then, copy `config.in' to
  7822. + `config.h', and copy `Makefile.in' to `Makefile'.
  7823. +    Next, edit both files.  Both files are liberally commented, and the
  7824. + necessary changes should be straightforward.
  7825. +    While editing `config.h', you need to determine what library
  7826. + routines you do or do not have by consulting your system documentation,
  7827. + or by perusing your actual libraries using the `ar' or `nm' utilities.
  7828. + In the worst case, simply do not define *any* of the macros for missing
  7829. + subroutines.  When you compile `gawk', the final link-editing step will
  7830. + fail.  The link editor will provide you with a list of unresolved
  7831. + external references--these are the missing subroutines.  Edit
  7832. + `config.h' again and recompile, and you should be set.
  7833. +    Editing the `Makefile' should also be straightforward.  Enable or
  7834. + disable the lines that begin with `##MAKE_WHATEVER##', as appropriate.
  7835. + Select the correct C compiler and `CFLAGS' for it.  Then run `make'.
  7836. +    Getting a correct configuration is likely to be an iterative process.
  7837. + Do not be discouraged if it takes you several tries.  If you have no
  7838. + luck whatsoever, please report your system type, and the steps you took.
  7839. + Once you do have a working configuration, please send it to the
  7840. + maintainers so that support for your system can be added to the
  7841. + official release.
  7842. +    *Note Reporting Problems and Bugs: Bugs, for information on how to
  7843. + report problems in configuring `gawk'.  You may also use the same
  7844. + mechanisms for sending in new configurations.
  7845. + 
  7846. + File: gawk.info,  Node: VMS Installation,  Next: MS-DOS Installation,  Prev: Unix Installation,  Up: Installation
  7847. + Compiling, Installing, and Running `gawk' on VMS
  7848. + ================================================
  7849. +    This section describes how to compile and install `gawk' under VMS.
  7850. + * Menu:
  7851. + * VMS Compilation::             How to compile `gawk' under VMS.
  7852. + * VMS Installation Details::    How to install `gawk' under VMS.
  7853. + * VMS Running::                 How to run `gawk' under VMS.
  7854. + * VMS POSIX::                   Alternate instructions for VMS POSIX.
  7855. + 
  7856. + File: gawk.info,  Node: VMS Compilation,  Next: VMS Installation Details,  Prev: VMS Installation,  Up: VMS Installation
  7857. + Compiling `gawk' under VMS
  7858. + --------------------------
  7859. +    To compile `gawk' under VMS, there is a `DCL' command procedure that
  7860. + will issue all the necessary `CC' and `LINK' commands, and there is
  7861. + also a `Makefile' for use with the `MMS' utility.  From the source
  7862. + directory, use either
  7863. +      $ @[.VMS]VMSBUILD.COM
  7864. + or
  7865. +      $ MMS/DESCRIPTION=[.VMS]DECSRIP.MMS GAWK
  7866. +    Depending upon which C compiler you are using, follow one of the sets
  7867. + of instructions in this table:
  7868. + VAX C V3.x
  7869. +      Use either `vmsbuild.com' or `descrip.mms' as is.  These use
  7870. +      `CC/OPTIMIZE=NOLINE', which is essential for Version 3.0.
  7871. + VAX C V2.x
  7872. +      You must have Version 2.3 or 2.4; older ones won't work.  Edit
  7873. +      either `vmsbuild.com' or `descrip.mms' according to the comments
  7874. +      in them.  For `vmsbuild.com', this just entails removing two `!'
  7875. +      delimiters.  Also edit `config.h' (which is a copy of file
  7876. +      `[.config]vms-conf.h') and comment out or delete the two lines
  7877. +      `#define __STDC__ 0' and `#define VAXC_BUILTINS' near the end.
  7878. + GNU C
  7879. +      Edit `vmsbuild.com' or `descrip.mms'; the changes are different
  7880. +      from those for VAX C V2.x, but equally straightforward.  No
  7881. +      changes to `config.h' should be needed.
  7882. + DEC C
  7883. +      Edit `vmsbuild.com' or `descrip.mms' according to their comments.
  7884. +      No changes to `config.h' should be needed.
  7885. +    `gawk' 2.15 has been tested under VAX/VMS 5.5-1 using VAX C V3.2,
  7886. + GNU C 1.40 and 2.3.  It should work without modifications for VMS V4.6
  7887. + and up.
  7888. + 
  7889. + File: gawk.info,  Node: VMS Installation Details,  Next: VMS Running,  Prev: VMS Compilation,  Up: VMS Installation
  7890. + Installing `gawk' on VMS
  7891. + ------------------------
  7892. +    To install `gawk', all you need is a "foreign" command, which is a
  7893. + `DCL' symbol whose value begins with a dollar sign.
  7894. +      $ GAWK :== $device:[directory]GAWK
  7895. + (Substitute the actual location of `gawk.exe' for
  7896. + `device:[directory]'.) The symbol should be placed in the `login.com'
  7897. + of any user who wishes to run `gawk', so that it will be defined every
  7898. + time the user logs on.  Alternatively, the symbol may be placed in the
  7899. + system-wide `sylogin.com' procedure, which will allow all users to run
  7900. + `gawk'.
  7901. +    Optionally, the help entry can be loaded into a VMS help library:
  7902. +      $ LIBRARY/HELP SYS$HELP:HELPLIB [.VMS]GAWK.HLP
  7903. + (You may want to substitute a site-specific help library rather than
  7904. + the standard VMS library `HELPLIB'.)  After loading the help text,
  7905. +      $ HELP GAWK
  7906. + will provide information about both the `gawk' implementation and the
  7907. + `awk' programming language.
  7908. +    The logical name `AWK_LIBRARY' can designate a default location for
  7909. + `awk' program files.  For the `-f' option, if the specified filename
  7910. + has no device or directory path information in it, `gawk' will look in
  7911. + the current directory first, then in the directory specified by the
  7912. + translation of `AWK_LIBRARY' if the file was not found.  If after
  7913. + searching in both directories, the file still is not found, then `gawk'
  7914. + appends the suffix `.awk' to the filename and the file search will be
  7915. + re-tried.  If `AWK_LIBRARY' is not defined, that portion of the file
  7916. + search will fail benignly.
  7917. + 
  7918. + File: gawk.info,  Node: VMS Running,  Next: VMS POSIX,  Prev: VMS Installation Details,  Up: VMS Installation
  7919. + Running `gawk' on VMS
  7920. + ---------------------
  7921. +    Command line parsing and quoting conventions are significantly
  7922. + different on VMS, so examples in this manual or from other sources
  7923. + often need minor changes.  They *are* minor though, and all `awk'
  7924. + programs should run correctly.
  7925. +    Here are a couple of trivial tests:
  7926. +      $ gawk -- "BEGIN {print ""Hello, World!""}"
  7927. +      $ gawk -"W" version     ! could also be -"W version" or "-W version"
  7928. + Note that upper-case and mixed-case text must be quoted.
  7929. +    The VMS port of `gawk' includes a `DCL'-style interface in addition
  7930. + to the original shell-style interface (see the help entry for details).
  7931. + One side-effect of dual command line parsing is that if there is only a
  7932. + single parameter (as in the quoted string program above), the command
  7933. + becomes ambiguous.  To work around this, the normally optional `--'
  7934. + flag is required to force Unix style rather than `DCL' parsing.  If any
  7935. + other dash-type options (or multiple parameters such as data files to be
  7936. + processed) are present, there is no ambiguity and `--' can be omitted.
  7937. +    The default search path when looking for `awk' program files
  7938. + specified by the `-f' option is `"SYS$DISK:[],AWK_LIBRARY:"'.  The
  7939. + logical name `AWKPATH' can be used to override this default.  The format
  7940. + of `AWKPATH' is a comma-separated list of directory specifications.
  7941. + When defining it, the value should be quoted so that it retains a single
  7942. + translation, and not a multi-translation `RMS' searchlist.
  7943. + 
  7944. + File: gawk.info,  Node: VMS POSIX,  Prev: VMS Running,  Up: VMS Installation
  7945. + Building and using `gawk' under VMS POSIX
  7946. + -----------------------------------------
  7947. +    Ignore the instructions above, although `vms/gawk.hlp' should still
  7948. + be made available in a help library.  Make sure that the two scripts,
  7949. + `configure' and `mungeconf', are executable; use `chmod +x' on them if
  7950. + necessary.  Then execute the following commands:
  7951. +      $ POSIX
  7952. +      psx> configure vms-posix
  7953. +      psx> make awktab.c gawk
  7954. + The first command will construct files `config.h' and `Makefile' out of
  7955. + templates.  The second command will compile and link `gawk'.  Due to a
  7956. + `make' bug in VMS POSIX V1.0 and V1.1, the file `awktab.c' must be
  7957. + given as an explicit target or it will not be built and the final link
  7958. + step will fail.  Ignore the warning `"Could not find lib m in lib
  7959. + list"'; it is harmless, caused by the explicit use of `-lm' as a linker
  7960. + option which is not needed under VMS POSIX.  Under V1.1 (but not V1.0)
  7961. + a problem with the `yacc' skeleton `/etc/yyparse.c' will cause a
  7962. + compiler warning for `awktab.c', followed by a linker warning about
  7963. + compilation warnings in the resulting object module.  These warnings
  7964. + can be ignored.
  7965. +    Once built, `gawk' will work like any other shell utility.  Unlike
  7966. + the normal VMS port of `gawk', no special command line manipulation is
  7967. + needed in the VMS POSIX environment.
  7968. + 
  7969. + File: gawk.info,  Node: MS-DOS Installation,  Next: Atari Installation,  Prev: VMS Installation,  Up: Installation
  7970. + Installing `gawk' on MS-DOS
  7971. + ===========================
  7972. +    The first step is to get all the files in the `gawk' distribution
  7973. + onto your PC.  Move all the files from the `pc' directory into the main
  7974. + directory where the other files are.  Edit the file `make.bat' so that
  7975. + it will be an acceptable MS-DOS batch file.  This means making sure
  7976. + that all lines are terminated with the ASCII carriage return and line
  7977. + feed characters.  restrictions.
  7978. +    `gawk' has only been compiled with version 5.1 of the Microsoft C
  7979. + compiler.  The file `make.bat' from the `pc' directory assumes that you
  7980. + have this compiler.
  7981. +    Copy the file `setargv.obj' from the library directory where it
  7982. + resides to the `gawk' source code directory.
  7983. +    Run `make.bat'.  This will compile `gawk' for you, and link it.
  7984. + That's all there is to it!
  7985. + 
  7986. + File: gawk.info,  Node: Atari Installation,  Prev: MS-DOS Installation,  Up: Installation
  7987. + Installing `gawk' on the Atari ST
  7988. + =================================
  7989. +    This section assumes that you are running TOS.  It applies to other
  7990. + Atari models (STe, TT) as well.
  7991. +    In order to use `gawk', you need to have a shell, either text or
  7992. + graphics, that does not map all the characters of a command line to
  7993. + upper case.  Maintaining case distinction in option flags is very
  7994. + important (*note Invoking `awk': Command Line.).  Popular shells like
  7995. + `gulam' or `gemini' will work, as will newer versions of `desktop'.
  7996. + Support for I/O redirection is necessary to make it easy to import
  7997. + `awk' programs from other environments.  Pipes are nice to have, but
  7998. + not vital.
  7999. +    If you have received an executable version of `gawk', place it, as
  8000. + usual, anywhere in your `PATH' where your shell will find it.
  8001. +    While executing, `gawk' creates a number of temporary files.  `gawk'
  8002. + looks for either of the environment variables `TEMP' or `TMPDIR', in
  8003. + that order.  If either one is found, its value is assumed to be a
  8004. + directory for temporary files.  This directory must exist, and if you
  8005. + can spare the memory, it is a good idea to put it on a RAM drive.  If
  8006. + neither `TEMP' nor `TMPDIR' are found, then `gawk' uses the current
  8007. + directory for its temporary files.
  8008. +    The ST version of `gawk' searches for its program files as described
  8009. + in *Note The `AWKPATH' Environment Variable: AWKPATH Variable.  On the
  8010. + ST, the default value for the `AWKPATH' variable is
  8011. + `".,c:\lib\awk,c:\gnu\lib\awk"'.  The search path can be modified by
  8012. + explicitly setting `AWKPATH' to whatever you wish.  Note that colons
  8013. + cannot be used on the ST to separate elements in the `AWKPATH'
  8014. + variable, since they have another, reserved, meaning.  Instead, you
  8015. + must use a comma to separate elements in the path.  If you are
  8016. + recompiling `gawk' on the ST, then you can choose a new default search
  8017. + path, by setting the value of `DEFPATH' in the file `...\config\atari'.
  8018. + You may choose a different separator character by setting the value of
  8019. + `ENVSEP' in the same file.  The new values will be used when creating
  8020. + the header file `config.h'.
  8021. +    Although `awk' allows great flexibility in doing I/O redirections
  8022. + from within a program, this facility should be used with care on the ST.
  8023. + In some circumstances the OS routines for file handle pool processing
  8024. + lose track of certain events, causing the computer to crash, and
  8025. + requiring a reboot.  Often a warm reboot is sufficient.  Fortunately,
  8026. + this happens infrequently, and in rather esoteric situations.  In
  8027. + particular, avoid having one part of an `awk' program using `print'
  8028. + statements explicitly redirected to `"/dev/stdout"', while other
  8029. + `print' statements use the default standard output, and a calling shell
  8030. + has redirected standard output to a file.
  8031. +    When `gawk' is compiled with the ST version of `gcc' and its usual
  8032. + libraries, it will accept both `/' and `\' as path separators.  While
  8033. + this is convenient, it should be remembered that this removes one,
  8034. + technically legal, character (`/') from your file names, and that it
  8035. + may create problems for external programs, called via the `system()'
  8036. + function, which may not support this convention.  Whenever it is
  8037. + possible that a file created by `gawk' will be used by some other
  8038. + program, use only backslashes.  Also remember that in `awk',
  8039. + backslashes in strings have to be doubled in order to get literal
  8040. + backslashes.
  8041. +    The initial port of `gawk' to the ST was done with `gcc'.  If you
  8042. + wish to recompile `gawk' from scratch, you will need to use a compiler
  8043. + that accepts ANSI standard C (such as `gcc', Turbo C, or Prospero C).
  8044. + If `sizeof(int) != sizeof(int *)', the correctness of the generated
  8045. + code depends heavily on the fact that all function calls have function
  8046. + prototypes in the current scope.  If your compiler does not accept
  8047. + function prototypes, you will probably have to add a number of casts to
  8048. + the code.
  8049. +    If you are using `gcc', make sure that you have up-to-date libraries.
  8050. + Older versions have problems with some library functions (`atan2()',
  8051. + `strftime()', the `%g' conversion in `sprintf()') which may affect the
  8052. + operation of `gawk'.
  8053. +    In the `atari' subdirectory of the `gawk' distribution is a version
  8054. + of the `system()' function that has been tested with `gulam' and `msh';
  8055. + it should work with other shells as well.  With `gulam', it passes the
  8056. + string to be executed without spawning an extra copy of a shell.  It is
  8057. + possible to replace this version of `system()' with a similar function
  8058. + from a library or from some other source if that version would be a
  8059. + better choice for the shell you prefer.
  8060. +    The files needed to recompile `gawk' on the ST can be found in the
  8061. + `atari' directory.  The provided files and instructions below assume
  8062. + that you have the GNU C compiler (`gcc'), the `gulam' shell, and an ST
  8063. + version of `sed'. The `Makefile' is set up to use `byacc' as a `yacc'
  8064. + replacement.  With a different set of tools some adjustments and/or
  8065. + editing will be needed.
  8066. +    `cd' to the `atari' directory.  Copy `Makefile.st' to `makefile' in
  8067. + the source (parent) directory.  Possibly adjust `../config/atari' to
  8068. + suit your system.  Execute the script `mkconf.g' which will create the
  8069. + header file `../config.h'.  Go back to the source directory.  If you
  8070. + are not using `gcc', check the file `missing.c'.  It may be necessary
  8071. + to change forward slashes in the references to files from the `atari'
  8072. + subdirectory into backslashes.  Type `make' and enjoy.
  8073. +    Compilation with `gcc' of some of the bigger modules, like
  8074. + `awk_tab.c', may require a full four megabytes of memory.  On smaller
  8075. + machines you would need to cut down on optimizations, or you would have
  8076. + to switch to another, less memory hungry, compiler.
  8077. + 
  8078. + File: gawk.info,  Node: Gawk Summary,  Next: Sample Program,  Prev: Installation,  Up: Top
  8079. + `gawk' Summary
  8080. + **************
  8081. +    This appendix provides a brief summary of the `gawk' command line
  8082. + and the `awk' language.  It is designed to serve as "quick reference."
  8083. + It is therefore terse, but complete.
  8084. + * Menu:
  8085. + * Command Line Summary::        Recapitulation of the command line.
  8086. + * Language Summary::            A terse review of the language.
  8087. + * Variables/Fields::            Variables, fields, and arrays.
  8088. + * Rules Summary::               Patterns and Actions, and their
  8089. +                                 component parts.
  8090. + * Functions Summary::           Defining and calling functions.
  8091. + * Historical Features::         Some undocumented but supported "features".
  8092. + 
  8093. + File: gawk.info,  Node: Command Line Summary,  Next: Language Summary,  Prev: Gawk Summary,  Up: Gawk Summary
  8094. + Command Line Options Summary
  8095. + ============================
  8096. +    The command line consists of options to `gawk' itself, the `awk'
  8097. + program text (if not supplied via the `-f' option), and values to be
  8098. + made available in the `ARGC' and `ARGV' predefined `awk' variables:
  8099. +      awk [POSIX OR GNU STYLE OPTIONS] -f source-file [`--'] FILE ...
  8100. +      awk [POSIX OR GNU STYLE OPTIONS] [`--'] 'PROGRAM' FILE ...
  8101. +    The options that `gawk' accepts are:
  8102. + `-F FS'
  8103. + `--field-separator=FS'
  8104. +      Use FS for the input field separator (the value of the `FS'
  8105. +      predefined variable).
  8106. + `-f PROGRAM-FILE'
  8107. + `--file=PROGRAM-FILE'
  8108. +      Read the `awk' program source from the file PROGRAM-FILE, instead
  8109. +      of from the first command line argument.
  8110. + `-v VAR=VAL'
  8111. + `--assign=VAR=VAL'
  8112. +      Assign the variable VAR the value VAL before program execution
  8113. +      begins.
  8114. + `-W compat'
  8115. + `--compat'
  8116. +      Specifies compatibility mode, in which `gawk' extensions are turned
  8117. +      off.
  8118. + `-W copyleft'
  8119. + `-W copyright'
  8120. + `--copyleft'
  8121. + `--copyright'
  8122. +      Print the short version of the General Public License on the error
  8123. +      output.  This option may disappear in a future version of `gawk'.
  8124. + `-W help'
  8125. + `-W usage'
  8126. + `--help'
  8127. + `--usage'
  8128. +      Print a relatively short summary of the available options on the
  8129. +      error output.
  8130. + `-W lint'
  8131. + `--lint'
  8132. +      Give warnings about dubious or non-portable `awk' constructs.
  8133. + `-W posix'
  8134. + `--posix'
  8135. +      Specifies POSIX compatibility mode, in which `gawk' extensions are
  8136. +      turned off and additional restrictions apply.
  8137. + `-W source=PROGRAM-TEXT'
  8138. + `--source=PROGRAM-TEXT'
  8139. +      Use PROGRAM-TEXT as `awk' program source code.  This option allows
  8140. +      mixing command line source code with source code from files, and is
  8141. +      particularly useful for mixing command line programs with library
  8142. +      functions.
  8143. + `-W version'
  8144. + `--version'
  8145. +      Print version information for this particular copy of `gawk' on
  8146. +      the error output.  This option may disappear in a future version
  8147. +      of `gawk'.
  8148. + `--'
  8149. +      Signal the end of options.  This is useful to allow further
  8150. +      arguments to the `awk' program itself to start with a `-'.  This
  8151. +      is mainly for consistency with the argument parsing conventions of
  8152. +      POSIX.
  8153. +    Any other options are flagged as invalid, but are otherwise ignored.
  8154. + *Note Invoking `awk': Command Line, for more details.
  8155. + 
  8156. + File: gawk.info,  Node: Language Summary,  Next: Variables/Fields,  Prev: Command Line Summary,  Up: Gawk Summary
  8157. + Language Summary
  8158. + ================
  8159. +    An `awk' program consists of a sequence of pattern-action statements
  8160. + and optional function definitions.
  8161. +      PATTERN    { ACTION STATEMENTS }
  8162. +      
  8163. +      function NAME(PARAMETER LIST)     { ACTION STATEMENTS }
  8164. +    `gawk' first reads the program source from the PROGRAM-FILE(s) if
  8165. + specified, or from the first non-option argument on the command line.
  8166. + The `-f' option may be used multiple times on the command line.  `gawk'
  8167. + reads the program text from all the PROGRAM-FILE files, effectively
  8168. + concatenating them in the order they are specified.  This is useful for
  8169. + building libraries of `awk' functions, without having to include them
  8170. + in each new `awk' program that uses them.  To use a library function in
  8171. + a file from a program typed in on the command line, specify `-f
  8172. + /dev/tty'; then type your program, and end it with a `Control-d'.
  8173. + *Note Invoking `awk': Command Line.
  8174. +    The environment variable `AWKPATH' specifies a search path to use
  8175. + when finding source files named with the `-f' option.  The default
  8176. + path, which is `.:/local/lib/awk:/gnu/lib/awk' is used if `AWKPATH' is
  8177. + not set.  If a file name given to the `-f' option contains a `/'
  8178. + character, no path search is performed.  *Note The `AWKPATH'
  8179. + Environment Variable: AWKPATH Variable, for a full description of the
  8180. + `AWKPATH' environment variable.
  8181. +    `gawk' compiles the program into an internal form, and then proceeds
  8182. + to read each file named in the `ARGV' array.  If there are no files
  8183. + named on the command line, `gawk' reads the standard input.
  8184. +    If a "file" named on the command line has the form `VAR=VAL', it is
  8185. + treated as a variable assignment: the variable VAR is assigned the
  8186. + value VAL.  If any of the files have a value that is the null string,
  8187. + that element in the list is skipped.
  8188. +    For each line in the input, `gawk' tests to see if it matches any
  8189. + PATTERN in the `awk' program.  For each pattern that the line matches,
  8190. + the associated ACTION is executed.
  8191. + 
  8192. + File: gawk.info,  Node: Variables/Fields,  Next: Rules Summary,  Prev: Language Summary,  Up: Gawk Summary
  8193. + Variables and Fields
  8194. + ====================
  8195. +    `awk' variables are dynamic; they come into existence when they are
  8196. + first used.  Their values are either floating-point numbers or strings.
  8197. + `awk' also has one-dimension arrays; multiple-dimensional arrays may be
  8198. + simulated.  There are several predefined variables that `awk' sets as a
  8199. + program runs; these are summarized below.
  8200. + * Menu:
  8201. + * Fields Summary::              Input field splitting.
  8202. + * Built-in Summary::            `awk''s built-in variables.
  8203. + * Arrays Summary::              Using arrays.
  8204. + * Data Type Summary::           Values in `awk' are numbers or strings.
  8205. + 
  8206. + File: gawk.info,  Node: Fields Summary,  Next: Built-in Summary,  Prev: Variables/Fields,  Up: Variables/Fields
  8207. + Fields
  8208. + ------
  8209. +    As each input line is read, `gawk' splits the line into FIELDS,
  8210. + using the value of the `FS' variable as the field separator.  If `FS'
  8211. + is a single character, fields are separated by that character.
  8212. + Otherwise, `FS' is expected to be a full regular expression.  In the
  8213. + special case that `FS' is a single blank, fields are separated by runs
  8214. + of blanks and/or tabs.  Note that the value of `IGNORECASE' (*note
  8215. + Case-sensitivity in Matching: Case-sensitivity.) also affects how
  8216. + fields are split when `FS' is a regular expression.
  8217. +    Each field in the input line may be referenced by its position, `$1',
  8218. + `$2', and so on.  `$0' is the whole line.  The value of a field may be
  8219. + assigned to as well.  Field numbers need not be constants:
  8220. +      n = 5
  8221. +      print $n
  8222. + prints the fifth field in the input line.  The variable `NF' is set to
  8223. + the total number of fields in the input line.
  8224. +    References to nonexistent fields (i.e., fields after `$NF') return
  8225. + the null-string.  However, assigning to a nonexistent field (e.g.,
  8226. + `$(NF+2) = 5') increases the value of `NF', creates any intervening
  8227. + fields with the null string as their value, and causes the value of
  8228. + `$0' to be recomputed, with the fields being separated by the value of
  8229. + `OFS'.
  8230. +    *Note Reading Input Files: Reading Files, for a full description of
  8231. + the way `awk' defines and uses fields.
  8232. + 
  8233. + File: gawk.info,  Node: Built-in Summary,  Next: Arrays Summary,  Prev: Fields Summary,  Up: Variables/Fields
  8234. + Built-in Variables
  8235. + ------------------
  8236. +    `awk''s built-in variables are:
  8237. + `ARGC'
  8238. +      The number of command line arguments (not including options or the
  8239. +      `awk' program itself).
  8240. + `ARGIND'
  8241. +      The index in `ARGV' of the current file being processed.  It is
  8242. +      always true that `FILENAME == ARGV[ARGIND]'.
  8243. + `ARGV'
  8244. +      The array of command line arguments.  The array is indexed from 0
  8245. +      to `ARGC' - 1.  Dynamically changing the contents of `ARGV' can
  8246. +      control the files used for data.
  8247. + `CONVFMT'
  8248. +      The conversion format to use when converting numbers to strings.
  8249. + `FIELDWIDTHS'
  8250. +      A space separated list of numbers describing the fixed-width input
  8251. +      data.
  8252. + `ENVIRON'
  8253. +      An array containing the values of the environment variables.  The
  8254. +      array is indexed by variable name, each element being the value of
  8255. +      that variable.  Thus, the environment variable `HOME' would be in
  8256. +      `ENVIRON["HOME"]'.  Its value might be `/u/close'.
  8257. +      Changing this array does not affect the environment seen by
  8258. +      programs which `gawk' spawns via redirection or the `system'
  8259. +      function.  (This may change in a future version of `gawk'.)
  8260. +      Some operating systems do not have environment variables.  The
  8261. +      array `ENVIRON' is empty when running on these systems.
  8262. + `ERRNO'
  8263. +      The system error message when an error occurs using `getline' or
  8264. +      `close'.
  8265. + `FILENAME'
  8266. +      The name of the current input file.  If no files are specified on
  8267. +      the command line, the value of `FILENAME' is `-'.
  8268. + `FNR'
  8269. +      The input record number in the current input file.
  8270. + `FS'
  8271. +      The input field separator, a blank by default.
  8272. + `IGNORECASE'
  8273. +      The case-sensitivity flag for regular expression operations.  If
  8274. +      `IGNORECASE' has a nonzero value, then pattern matching in rules,
  8275. +      field splitting with `FS', regular expression matching with `~'
  8276. +      and `!~', and the `gsub', `index', `match', `split' and `sub'
  8277. +      predefined functions all ignore case when doing regular expression
  8278. +      operations.
  8279. + `NF'
  8280. +      The number of fields in the current input record.
  8281. + `NR'
  8282. +      The total number of input records seen so far.
  8283. + `OFMT'
  8284. +      The output format for numbers for the `print' statement, `"%.6g"'
  8285. +      by default.
  8286. + `OFS'
  8287. +      The output field separator, a blank by default.
  8288. + `ORS'
  8289. +      The output record separator, by default a newline.
  8290. + `RS'
  8291. +      The input record separator, by default a newline.  `RS' is
  8292. +      exceptional in that only the first character of its string value
  8293. +      is used for separating records.  If `RS' is set to the null
  8294. +      string, then records are separated by blank lines.  When `RS' is
  8295. +      set to the null string, then the newline character always acts as
  8296. +      a field separator, in addition to whatever value `FS' may have.
  8297. + `RSTART'
  8298. +      The index of the first character matched by `match'; 0 if no match.
  8299. + `RLENGTH'
  8300. +      The length of the string matched by `match'; -1 if no match.
  8301. + `SUBSEP'
  8302. +      The string used to separate multiple subscripts in array elements,
  8303. +      by default `"\034"'.
  8304. +    *Note Built-in Variables::, for more information.
  8305. + 
  8306. + File: gawk.info,  Node: Arrays Summary,  Next: Data Type Summary,  Prev: Built-in Summary,  Up: Variables/Fields
  8307. + Arrays
  8308. + ------
  8309. +    Arrays are subscripted with an expression between square brackets
  8310. + (`[' and `]').  Array subscripts are *always* strings; numbers are
  8311. + converted to strings as necessary, following the standard conversion
  8312. + rules (*note Conversion of Strings and Numbers: Conversion.).
  8313. +    If you use multiple expressions separated by commas inside the square
  8314. + brackets, then the array subscript is a string consisting of the
  8315. + concatenation of the individual subscript values, converted to strings,
  8316. + separated by the subscript separator (the value of `SUBSEP').
  8317. +    The special operator `in' may be used in an `if' or `while'
  8318. + statement to see if an array has an index consisting of a particular
  8319. + value.
  8320. +      if (val in array)
  8321. +              print array[val]
  8322. +    If the array has multiple subscripts, use `(i, j, ...) in array' to
  8323. + test for existence of an element.
  8324. +    The `in' construct may also be used in a `for' loop to iterate over
  8325. + all the elements of an array.  *Note Scanning all Elements of an Array:
  8326. + Scanning an Array.
  8327. +    An element may be deleted from an array using the `delete' statement.
  8328. +    *Note Arrays in `awk': Arrays, for more detailed information.
  8329. + 
  8330. + File: gawk.info,  Node: Data Type Summary,  Prev: Arrays Summary,  Up: Variables/Fields
  8331. + Data Types
  8332. + ----------
  8333. +    The value of an `awk' expression is always either a number or a
  8334. + string.
  8335. +    Certain contexts (such as arithmetic operators) require numeric
  8336. + values.  They convert strings to numbers by interpreting the text of
  8337. + the string as a numeral.  If the string does not look like a numeral,
  8338. + it converts to 0.
  8339. +    Certain contexts (such as concatenation) require string values.
  8340. + They convert numbers to strings by effectively printing them with
  8341. + `sprintf'.  *Note Conversion of Strings and Numbers: Conversion, for
  8342. + the details.
  8343. +    To force conversion of a string value to a number, simply add 0 to
  8344. + it.  If the value you start with is already a number, this does not
  8345. + change it.
  8346. +    To force conversion of a numeric value to a string, concatenate it
  8347. + with the null string.
  8348. +    The `awk' language defines comparisons as being done numerically if
  8349. + both operands are numeric, or if one is numeric and the other is a
  8350. + numeric string.  Otherwise one or both operands are converted to
  8351. + strings and a string comparison is performed.
  8352. +    Uninitialized variables have the string value `""' (the null, or
  8353. + empty, string).  In contexts where a number is required, this is
  8354. + equivalent to 0.
  8355. +    *Note Variables::, for more information on variable naming and
  8356. + initialization; *note Conversion of Strings and Numbers: Conversion.,
  8357. + for more information on how variable values are interpreted.
  8358. + 
  8359. + File: gawk.info,  Node: Rules Summary,  Next: Functions Summary,  Prev: Variables/Fields,  Up: Gawk Summary
  8360. + Patterns and Actions
  8361. + ====================
  8362. + * Menu:
  8363. + * Pattern Summary::             Quick overview of patterns.
  8364. + * Regexp Summary::              Quick overview of regular expressions.
  8365. + * Actions Summary::             Quick overview of actions.
  8366. +    An `awk' program is mostly composed of rules, each consisting of a
  8367. + pattern followed by an action.  The action is enclosed in `{' and `}'.
  8368. + Either the pattern may be missing, or the action may be missing, but,
  8369. + of course, not both.  If the pattern is missing, the action is executed
  8370. + for every single line of input.  A missing action is equivalent to this
  8371. + action,
  8372. +      { print }
  8373. + which prints the entire line.
  8374. +    Comments begin with the `#' character, and continue until the end of
  8375. + the line.  Blank lines may be used to separate statements.  Normally, a
  8376. + statement ends with a newline, however, this is not the case for lines
  8377. + ending in a `,', `{', `?', `:', `&&', or `||'.  Lines ending in `do' or
  8378. + `else' also have their statements automatically continued on the
  8379. + following line.  In other cases, a line can be continued by ending it
  8380. + with a `\', in which case the newline is ignored.
  8381. +    Multiple statements may be put on one line by separating them with a
  8382. + `;'.  This applies to both the statements within the action part of a
  8383. + rule (the usual case), and to the rule statements.
  8384. +    *Note Comments in `awk' Programs: Comments, for information on
  8385. + `awk''s commenting convention; *note `awk' Statements versus Lines:
  8386. + Statements/Lines., for a description of the line continuation mechanism
  8387. + in `awk'.
  8388. + 
  8389. + File: gawk.info,  Node: Pattern Summary,  Next: Regexp Summary,  Prev: Rules Summary,  Up: Rules Summary
  8390. + Patterns
  8391. + --------
  8392. +    `awk' patterns may be one of the following:
  8393. +      /REGULAR EXPRESSION/
  8394. +      RELATIONAL EXPRESSION
  8395. +      PATTERN && PATTERN
  8396. +      PATTERN || PATTERN
  8397. +      PATTERN ? PATTERN : PATTERN
  8398. +      (PATTERN)
  8399. +      ! PATTERN
  8400. +      PATTERN1, PATTERN2
  8401. +      BEGIN
  8402. +      END
  8403. +    `BEGIN' and `END' are two special kinds of patterns that are not
  8404. + tested against the input.  The action parts of all `BEGIN' rules are
  8405. + merged as if all the statements had been written in a single `BEGIN'
  8406. + rule.  They are executed before any of the input is read.  Similarly,
  8407. + all the `END' rules are merged, and executed when all the input is
  8408. + exhausted (or when an `exit' statement is executed).  `BEGIN' and `END'
  8409. + patterns cannot be combined with other patterns in pattern expressions.
  8410. + `BEGIN' and `END' rules cannot have missing action parts.
  8411. +    For `/REGULAR-EXPRESSION/' patterns, the associated statement is
  8412. + executed for each input line that matches the regular expression.
  8413. + Regular expressions are extensions of those in `egrep', and are
  8414. + summarized below.
  8415. +    A RELATIONAL EXPRESSION may use any of the operators defined below in
  8416. + the section on actions.  These generally test whether certain fields
  8417. + match certain regular expressions.
  8418. +    The `&&', `||', and `!' operators are logical "and," logical "or,"
  8419. + and logical "not," respectively, as in C.  They do short-circuit
  8420. + evaluation, also as in C, and are used for combining more primitive
  8421. + pattern expressions.  As in most languages, parentheses may be used to
  8422. + change the order of evaluation.
  8423. +    The `?:' operator is like the same operator in C.  If the first
  8424. + pattern matches, then the second pattern is matched against the input
  8425. + record; otherwise, the third is matched.  Only one of the second and
  8426. + third patterns is matched.
  8427. +    The `PATTERN1, PATTERN2' form of a pattern is called a range
  8428. + pattern.  It matches all input lines starting with a line that matches
  8429. + PATTERN1, and continuing until a line that matches PATTERN2, inclusive.
  8430. + A range pattern cannot be used as an operand to any of the pattern
  8431. + operators.
  8432. +    *Note Patterns::, for a full description of the pattern part of `awk'
  8433. + rules.
  8434. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-8 gawk-2.15.5/gawk.info-8
  8435. *** /src/baseline/gawk-2.15.5/gawk.info-8    Thu Jan  1 00:00:00 1970
  8436. --- gawk-2.15.5/gawk.info-8    Sun Jun 12 22:28:55 1994
  8437. ***************
  8438. *** 0 ****
  8439. --- 1,1173 ----
  8440. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  8441. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  8442. +    This file documents `awk', a program that you can use to select
  8443. + particular records in a file and perform operations upon them.
  8444. +    This is Edition 0.15 of `The GAWK Manual',
  8445. + for the 2.15 version of the GNU implementation
  8446. + of AWK.
  8447. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  8448. +    Permission is granted to make and distribute verbatim copies of this
  8449. + manual provided the copyright notice and this permission notice are
  8450. + preserved on all copies.
  8451. +    Permission is granted to copy and distribute modified versions of
  8452. + this manual under the conditions for verbatim copying, provided that
  8453. + the entire resulting derived work is distributed under the terms of a
  8454. + permission notice identical to this one.
  8455. +    Permission is granted to copy and distribute translations of this
  8456. + manual into another language, under the above conditions for modified
  8457. + versions, except that this permission notice may be stated in a
  8458. + translation approved by the Foundation.
  8459. + 
  8460. + File: gawk.info,  Node: Regexp Summary,  Next: Actions Summary,  Prev: Pattern Summary,  Up: Rules Summary
  8461. + Regular Expressions
  8462. + -------------------
  8463. +    Regular expressions are the extended kind found in `egrep'.  They
  8464. + are composed of characters as follows:
  8465. + `C'
  8466. +      matches the character C (assuming C is a character with no special
  8467. +      meaning in regexps).
  8468. + `\C'
  8469. +      matches the literal character C.
  8470. + `.'
  8471. +      matches any character except newline.
  8472. + `^'
  8473. +      matches the beginning of a line or a string.
  8474. + `$'
  8475. +      matches the end of a line or a string.
  8476. + `[ABC...]'
  8477. +      matches any of the characters ABC... (character class).
  8478. + `[^ABC...]'
  8479. +      matches any character except ABC... and newline (negated character
  8480. +      class).
  8481. + `R1|R2'
  8482. +      matches either R1 or R2 (alternation).
  8483. + `R1R2'
  8484. +      matches R1, and then R2 (concatenation).
  8485. + `R+'
  8486. +      matches one or more R's.
  8487. + `R*'
  8488. +      matches zero or more R's.
  8489. + `R?'
  8490. +      matches zero or one R's.
  8491. + `(R)'
  8492. +      matches R (grouping).
  8493. +    *Note Regular Expressions as Patterns: Regexp, for a more detailed
  8494. + explanation of regular expressions.
  8495. +    The escape sequences allowed in string constants are also valid in
  8496. + regular expressions (*note Constant Expressions: Constants.).
  8497. + 
  8498. + File: gawk.info,  Node: Actions Summary,  Prev: Regexp Summary,  Up: Rules Summary
  8499. + Actions
  8500. + -------
  8501. +    Action statements are enclosed in braces, `{' and `}'.  Action
  8502. + statements consist of the usual assignment, conditional, and looping
  8503. + statements found in most languages.  The operators, control statements,
  8504. + and input/output statements available are patterned after those in C.
  8505. + * Menu:
  8506. + * Operator Summary::            `awk' operators.
  8507. + * Control Flow Summary::        The control statements.
  8508. + * I/O Summary::                 The I/O statements.
  8509. + * Printf Summary::              A summary of `printf'.
  8510. + * Special File Summary::        Special file names interpreted internally.
  8511. + * Numeric Functions Summary::   Built-in numeric functions.
  8512. + * String Functions Summary::    Built-in string functions.
  8513. + * Time Functions Summary::      Built-in time functions.
  8514. + * String Constants Summary::    Escape sequences in strings.
  8515. + 
  8516. + File: gawk.info,  Node: Operator Summary,  Next: Control Flow Summary,  Prev: Actions Summary,  Up: Actions Summary
  8517. + Operators
  8518. + .........
  8519. +    The operators in `awk', in order of increasing precedence, are:
  8520. + `= += -= *= /= %= ^='
  8521. +      Assignment.  Both absolute assignment (`VAR=VALUE') and operator
  8522. +      assignment (the other forms) are supported.
  8523. + `?:'
  8524. +      A conditional expression, as in C.  This has the form `EXPR1 ?
  8525. +      eXPR2 : EXPR3'.  If EXPR1 is true, the value of the expression is
  8526. +      EXPR2; otherwise it is EXPR3.  Only one of EXPR2 and EXPR3 is
  8527. +      evaluated.
  8528. + `||'
  8529. +      Logical "or".
  8530. + `&&'
  8531. +      Logical "and".
  8532. + `~ !~'
  8533. +      Regular expression match, negated match.
  8534. + `< <= > >= != =='
  8535. +      The usual relational operators.
  8536. + `BLANK'
  8537. +      String concatenation.
  8538. + `+ -'
  8539. +      Addition and subtraction.
  8540. + `* / %'
  8541. +      Multiplication, division, and modulus.
  8542. + `+ - !'
  8543. +      Unary plus, unary minus, and logical negation.
  8544. + `^'
  8545. +      Exponentiation (`**' may also be used, and `**=' for the assignment
  8546. +      operator, but they are not specified in the POSIX standard).
  8547. + `++ --'
  8548. +      Increment and decrement, both prefix and postfix.
  8549. + `$'
  8550. +      Field reference.
  8551. +    *Note Expressions as Action Statements: Expressions, for a full
  8552. + description of all the operators listed above.  *Note Examining Fields:
  8553. + Fields, for a description of the field reference operator.
  8554. + 
  8555. + File: gawk.info,  Node: Control Flow Summary,  Next: I/O Summary,  Prev: Operator Summary,  Up: Actions Summary
  8556. + Control Statements
  8557. + ..................
  8558. +    The control statements are as follows:
  8559. +      if (CONDITION) STATEMENT [ else STATEMENT ]
  8560. +      while (CONDITION) STATEMENT
  8561. +      do STATEMENT while (CONDITION)
  8562. +      for (EXPR1; EXPR2; EXPR3) STATEMENT
  8563. +      for (VAR in ARRAY) STATEMENT
  8564. +      break
  8565. +      continue
  8566. +      delete ARRAY[INDEX]
  8567. +      exit [ EXPRESSION ]
  8568. +      { STATEMENTS }
  8569. +    *Note Control Statements in Actions: Statements, for a full
  8570. + description of all the control statements listed above.
  8571. + 
  8572. + File: gawk.info,  Node: I/O Summary,  Next: Printf Summary,  Prev: Control Flow Summary,  Up: Actions Summary
  8573. + I/O Statements
  8574. + ..............
  8575. +    The input/output statements are as follows:
  8576. + `getline'
  8577. +      Set `$0' from next input record; set `NF', `NR', `FNR'.
  8578. + `getline <FILE'
  8579. +      Set `$0' from next record of FILE; set `NF'.
  8580. + `getline VAR'
  8581. +      Set VAR from next input record; set `NF', `FNR'.
  8582. + `getline VAR <FILE'
  8583. +      Set VAR from next record of FILE.
  8584. + `next'
  8585. +      Stop processing the current input record.  The next input record
  8586. +      is read and processing starts over with the first pattern in the
  8587. +      `awk' program.  If the end of the input data is reached, the `END'
  8588. +      rule(s), if any, are executed.
  8589. + `next file'
  8590. +      Stop processing the current input file.  The next input record
  8591. +      read comes from the next input file.  `FILENAME' is updated, `FNR'
  8592. +      is set to 1, and processing starts over with the first pattern in
  8593. +      the `awk' program.  If the end of the input data is reached, the
  8594. +      `END' rule(s), if any, are executed.
  8595. + `print'
  8596. +      Prints the current record.
  8597. + `print EXPR-LIST'
  8598. +      Prints expressions.
  8599. + `print EXPR-LIST > FILE'
  8600. +      Prints expressions on FILE.
  8601. + `printf FMT, EXPR-LIST'
  8602. +      Format and print.
  8603. + `printf FMT, EXPR-LIST > file'
  8604. +      Format and print on FILE.
  8605. +    Other input/output redirections are also allowed.  For `print' and
  8606. + `printf', `>> FILE' appends output to the FILE, and `| COMMAND' writes
  8607. + on a pipe.  In a similar fashion, `COMMAND | getline' pipes input into
  8608. + `getline'.  `getline' returns 0 on end of file, and -1 on an error.
  8609. +    *Note Explicit Input with `getline': Getline, for a full description
  8610. + of the `getline' statement.  *Note Printing Output: Printing, for a
  8611. + full description of `print' and `printf'.  Finally, *note The `next'
  8612. + Statement: Next Statement., for a description of how the `next'
  8613. + statement works.
  8614. + 
  8615. + File: gawk.info,  Node: Printf Summary,  Next: Special File Summary,  Prev: I/O Summary,  Up: Actions Summary
  8616. + `printf' Summary
  8617. + ................
  8618. +    The `awk' `printf' statement and `sprintf' function accept the
  8619. + following conversion specification formats:
  8620. + `%c'
  8621. +      An ASCII character.  If the argument used for `%c' is numeric, it
  8622. +      is treated as a character and printed.  Otherwise, the argument is
  8623. +      assumed to be a string, and the only first character of that
  8624. +      string is printed.
  8625. + `%d'
  8626. + `%i'
  8627. +      A decimal number (the integer part).
  8628. + `%e'
  8629. +      A floating point number of the form `[-]d.ddddddE[+-]dd'.
  8630. + `%f'
  8631. +      A floating point number of the form [`-']`ddd.dddddd'.
  8632. + `%g'
  8633. +      Use `%e' or `%f' conversion, whichever produces a shorter string,
  8634. +      with nonsignificant zeros suppressed.
  8635. + `%o'
  8636. +      An unsigned octal number (again, an integer).
  8637. + `%s'
  8638. +      A character string.
  8639. + `%x'
  8640. +      An unsigned hexadecimal number (an integer).
  8641. + `%X'
  8642. +      Like `%x', except use `A' through `F' instead of `a' through `f'
  8643. +      for decimal 10 through 15.
  8644. + `%%'
  8645. +      A single `%' character; no argument is converted.
  8646. +    There are optional, additional parameters that may lie between the
  8647. + `%' and the control letter:
  8648. + `-'
  8649. +      The expression should be left-justified within its field.
  8650. + `WIDTH'
  8651. +      The field should be padded to this width.  If WIDTH has a leading
  8652. +      zero, then the field is padded with zeros.  Otherwise it is padded
  8653. +      with blanks.
  8654. + `.PREC'
  8655. +      A number indicating the maximum width of strings or digits to the
  8656. +      right of the decimal point.
  8657. +    Either or both of the WIDTH and PREC values may be specified as `*'.
  8658. + In that case, the particular value is taken from the argument list.
  8659. +    *Note Using `printf' Statements for Fancier Printing: Printf, for
  8660. + examples and for a more detailed description.
  8661. + 
  8662. + File: gawk.info,  Node: Special File Summary,  Next: Numeric Functions Summary,  Prev: Printf Summary,  Up: Actions Summary
  8663. + Special File Names
  8664. + ..................
  8665. +    When doing I/O redirection from either `print' or `printf' into a
  8666. + file, or via `getline' from a file, `gawk' recognizes certain special
  8667. + file names internally.  These file names allow access to open file
  8668. + descriptors inherited from `gawk''s parent process (usually the shell).
  8669. + The file names are:
  8670. + `/dev/stdin'
  8671. +      The standard input.
  8672. + `/dev/stdout'
  8673. +      The standard output.
  8674. + `/dev/stderr'
  8675. +      The standard error output.
  8676. + `/dev/fd/N'
  8677. +      The file denoted by the open file descriptor N.
  8678. +    In addition the following files provide process related information
  8679. + about the running `gawk' program.
  8680. + `/dev/pid'
  8681. +      Reading this file returns the process ID of the current process,
  8682. +      in decimal, terminated with a newline.
  8683. + `/dev/ppid'
  8684. +      Reading this file returns the parent process ID of the current
  8685. +      process, in decimal, terminated with a newline.
  8686. + `/dev/pgrpid'
  8687. +      Reading this file returns the process group ID of the current
  8688. +      process, in decimal, terminated with a newline.
  8689. + `/dev/user'
  8690. +      Reading this file returns a single record terminated with a
  8691. +      newline.  The fields are separated with blanks.  The fields
  8692. +      represent the following information:
  8693. +     `$1'
  8694. +           The value of the `getuid' system call.
  8695. +     `$2'
  8696. +           The value of the `geteuid' system call.
  8697. +     `$3'
  8698. +           The value of the `getgid' system call.
  8699. +     `$4'
  8700. +           The value of the `getegid' system call.
  8701. +      If there are any additional fields, they are the group IDs
  8702. +      returned by `getgroups' system call.  (Multiple groups may not be
  8703. +      supported on all systems.)
  8704. + These file names may also be used on the command line to name data
  8705. + files.  These file names are only recognized internally if you do not
  8706. + actually have files by these names on your system.
  8707. +    *Note Standard I/O Streams: Special Files, for a longer description
  8708. + that provides the motivation for this feature.
  8709. + 
  8710. + File: gawk.info,  Node: Numeric Functions Summary,  Next: String Functions Summary,  Prev: Special File Summary,  Up: Actions Summary
  8711. + Numeric Functions
  8712. + .................
  8713. +    `awk' has the following predefined arithmetic functions:
  8714. + `atan2(Y, X)'
  8715. +      returns the arctangent of Y/X in radians.
  8716. + `cos(EXPR)'
  8717. +      returns the cosine in radians.
  8718. + `exp(EXPR)'
  8719. +      the exponential function.
  8720. + `int(EXPR)'
  8721. +      truncates to integer.
  8722. + `log(EXPR)'
  8723. +      the natural logarithm function.
  8724. + `rand()'
  8725. +      returns a random number between 0 and 1.
  8726. + `sin(EXPR)'
  8727. +      returns the sine in radians.
  8728. + `sqrt(EXPR)'
  8729. +      the square root function.
  8730. + `srand(EXPR)'
  8731. +      use EXPR as a new seed for the random number generator.  If no EXPR
  8732. +      is provided, the time of day is used.  The return value is the
  8733. +      previous seed for the random number generator.
  8734. + 
  8735. + File: gawk.info,  Node: String Functions Summary,  Next: Time Functions Summary,  Prev: Numeric Functions Summary,  Up: Actions Summary
  8736. + String Functions
  8737. + ................
  8738. +    `awk' has the following predefined string functions:
  8739. + `gsub(R, S, T)'
  8740. +      for each substring matching the regular expression R in the string
  8741. +      T, substitute the string S, and return the number of substitutions.
  8742. +      If T is not supplied, use `$0'.
  8743. + `index(S, T)'
  8744. +      returns the index of the string T in the string S, or 0 if T is
  8745. +      not present.
  8746. + `length(S)'
  8747. +      returns the length of the string S.  The length of `$0' is
  8748. +      returned if no argument is supplied.
  8749. + `match(S, R)'
  8750. +      returns the position in S where the regular expression R occurs,
  8751. +      or 0 if R is not present, and sets the values of `RSTART' and
  8752. +      `RLENGTH'.
  8753. + `split(S, A, R)'
  8754. +      splits the string S into the array A on the regular expression R,
  8755. +      and returns the number of fields.  If R is omitted, `FS' is used
  8756. +      instead.
  8757. + `sprintf(FMT, EXPR-LIST)'
  8758. +      prints EXPR-LIST according to FMT, and returns the resulting
  8759. +      string.
  8760. + `sub(R, S, T)'
  8761. +      this is just like `gsub', but only the first matching substring is
  8762. +      replaced.
  8763. + `substr(S, I, N)'
  8764. +      returns the N-character substring of S starting at I.  If N is
  8765. +      omitted, the rest of S is used.
  8766. + `tolower(STR)'
  8767. +      returns a copy of the string STR, with all the upper-case
  8768. +      characters in STR translated to their corresponding lower-case
  8769. +      counterparts.  Nonalphabetic characters are left unchanged.
  8770. + `toupper(STR)'
  8771. +      returns a copy of the string STR, with all the lower-case
  8772. +      characters in STR translated to their corresponding upper-case
  8773. +      counterparts.  Nonalphabetic characters are left unchanged.
  8774. + `system(CMD-LINE)'
  8775. +      Execute the command CMD-LINE, and return the exit status.
  8776. + 
  8777. + File: gawk.info,  Node: Time Functions Summary,  Next: String Constants Summary,  Prev: String Functions Summary,  Up: Actions Summary
  8778. + Built-in time functions
  8779. + .......................
  8780. +    The following two functions are available for getting the current
  8781. + time of day, and for formatting time stamps.
  8782. + `systime()'
  8783. +      returns the current time of day as the number of seconds since a
  8784. +      particular epoch (Midnight, January 1, 1970 UTC, on POSIX systems).
  8785. + `strftime(FORMAT, TIMESTAMP)'
  8786. +      formats TIMESTAMP according to the specification in FORMAT.  The
  8787. +      current time of day is used if no TIMESTAMP is supplied.  *Note
  8788. +      Functions for Dealing with Time Stamps: Time Functions, for the
  8789. +      details on the conversion specifiers that `strftime' accepts.
  8790. + 
  8791. + File: gawk.info,  Node: String Constants Summary,  Prev: Time Functions Summary,  Up: Actions Summary
  8792. + String Constants
  8793. + ................
  8794. +    String constants in `awk' are sequences of characters enclosed
  8795. + between double quotes (`"').  Within strings, certain "escape sequences"
  8796. + are recognized, as in C.  These are:
  8797. + `\\'
  8798. +      A literal backslash.
  8799. + `\a'
  8800. +      The "alert" character; usually the ASCII BEL character.
  8801. + `\b'
  8802. +      Backspace.
  8803. + `\f'
  8804. +      Formfeed.
  8805. + `\n'
  8806. +      Newline.
  8807. + `\r'
  8808. +      Carriage return.
  8809. + `\t'
  8810. +      Horizontal tab.
  8811. + `\v'
  8812. +      Vertical tab.
  8813. + `\xHEX DIGITS'
  8814. +      The character represented by the string of hexadecimal digits
  8815. +      following the `\x'.  As in ANSI C, all following hexadecimal
  8816. +      digits are considered part of the escape sequence.  (This feature
  8817. +      should tell us something about language design by committee.)
  8818. +      E.g., `"\x1B"' is a string containing the ASCII ESC (escape)
  8819. +      character.  (The `\x' escape sequence is not in POSIX `awk'.)
  8820. + `\DDD'
  8821. +      The character represented by the 1-, 2-, or 3-digit sequence of
  8822. +      octal digits.  Thus, `"\033"' is also a string containing the
  8823. +      ASCII ESC (escape) character.
  8824. + `\C'
  8825. +      The literal character C.
  8826. +    The escape sequences may also be used inside constant regular
  8827. + expressions (e.g., the regexp `/[ \t\f\n\r\v]/' matches whitespace
  8828. + characters).
  8829. +    *Note Constant Expressions: Constants.
  8830. + 
  8831. + File: gawk.info,  Node: Functions Summary,  Next: Historical Features,  Prev: Rules Summary,  Up: Gawk Summary
  8832. + Functions
  8833. + =========
  8834. +    Functions in `awk' are defined as follows:
  8835. +      function NAME(PARAMETER LIST) { STATEMENTS }
  8836. +    Actual parameters supplied in the function call are used to
  8837. + instantiate the formal parameters declared in the function.  Arrays are
  8838. + passed by reference, other variables are passed by value.
  8839. +    If there are fewer arguments passed than there are names in
  8840. + PARAMETER-LIST, the extra names are given the null string as value.
  8841. + Extra names have the effect of local variables.
  8842. +    The open-parenthesis in a function call of a user-defined function
  8843. + must immediately follow the function name, without any intervening
  8844. + white space.  This is to avoid a syntactic ambiguity with the
  8845. + concatenation operator.
  8846. +    The word `func' may be used in place of `function' (but not in POSIX
  8847. + `awk').
  8848. +    Use the `return' statement to return a value from a function.
  8849. +    *Note User-defined Functions: User-defined, for a more complete
  8850. + description.
  8851. + 
  8852. + File: gawk.info,  Node: Historical Features,  Prev: Functions Summary,  Up: Gawk Summary
  8853. + Historical Features
  8854. + ===================
  8855. +    There are two features of historical `awk' implementations that
  8856. + `gawk' supports.  First, it is possible to call the `length' built-in
  8857. + function not only with no arguments, but even without parentheses!
  8858. +      a = length
  8859. + is the same as either of
  8860. +      a = length()
  8861. +      a = length($0)
  8862. + This feature is marked as "deprecated" in the POSIX standard, and
  8863. + `gawk' will issue a warning about its use if `-W lint' is specified on
  8864. + the command line.
  8865. +    The other feature is the use of the `continue' statement outside the
  8866. + body of a `while', `for', or `do' loop.  Traditional `awk'
  8867. + implementations have treated such usage as equivalent to the `next'
  8868. + statement.  `gawk' will support this usage if `-W posix' has not been
  8869. + specified.
  8870. + 
  8871. + File: gawk.info,  Node: Sample Program,  Next: Bugs,  Prev: Gawk Summary,  Up: Top
  8872. + Sample Program
  8873. + **************
  8874. +    The following example is a complete `awk' program, which prints the
  8875. + number of occurrences of each word in its input.  It illustrates the
  8876. + associative nature of `awk' arrays by using strings as subscripts.  It
  8877. + also demonstrates the `for X in ARRAY' construction.  Finally, it shows
  8878. + how `awk' can be used in conjunction with other utility programs to do
  8879. + a useful task of some complexity with a minimum of effort.  Some
  8880. + explanations follow the program listing.
  8881. +      awk '
  8882. +      # Print list of word frequencies
  8883. +      {
  8884. +          for (i = 1; i <= NF; i++)
  8885. +              freq[$i]++
  8886. +      }
  8887. +      
  8888. +      END {
  8889. +          for (word in freq)
  8890. +              printf "%s\t%d\n", word, freq[word]
  8891. +      }'
  8892. +    The first thing to notice about this program is that it has two
  8893. + rules.  The first rule, because it has an empty pattern, is executed on
  8894. + every line of the input.  It uses `awk''s field-accessing mechanism
  8895. + (*note Examining Fields: Fields.) to pick out the individual words from
  8896. + the line, and the built-in variable `NF' (*note Built-in Variables::.)
  8897. + to know how many fields are available.
  8898. +    For each input word, an element of the array `freq' is incremented to
  8899. + reflect that the word has been seen an additional time.
  8900. +    The second rule, because it has the pattern `END', is not executed
  8901. + until the input has been exhausted.  It prints out the contents of the
  8902. + `freq' table that has been built up inside the first action.
  8903. +    Note that this program has several problems that would prevent it
  8904. + from being useful by itself on real text files:
  8905. +    * Words are detected using the `awk' convention that fields are
  8906. +      separated by whitespace and that other characters in the input
  8907. +      (except newlines) don't have any special meaning to `awk'.  This
  8908. +      means that punctuation characters count as part of words.
  8909. +    * The `awk' language considers upper and lower case characters to be
  8910. +      distinct.  Therefore, `foo' and `Foo' are not treated by this
  8911. +      program as the same word.  This is undesirable since in normal
  8912. +      text, words are capitalized if they begin sentences, and a
  8913. +      frequency analyzer should not be sensitive to that.
  8914. +    * The output does not come out in any useful order.  You're more
  8915. +      likely to be interested in which words occur most frequently, or
  8916. +      having an alphabetized table of how frequently each word occurs.
  8917. +    The way to solve these problems is to use some of the more advanced
  8918. + features of the `awk' language.  First, we use `tolower' to remove case
  8919. + distinctions.  Next, we use `gsub' to remove punctuation characters.
  8920. + Finally, we use the system `sort' utility to process the output of the
  8921. + `awk' script.  First, here is the new version of the program:
  8922. +      awk '
  8923. +      # Print list of word frequencies
  8924. +      {
  8925. +          $0 = tolower($0)    # remove case distinctions
  8926. +          gsub(/[^a-z0-9_ \t]/, "", $0)  # remove punctuation
  8927. +          for (i = 1; i <= NF; i++)
  8928. +              freq[$i]++
  8929. +      }
  8930. +      
  8931. +      END {
  8932. +          for (word in freq)
  8933. +              printf "%s\t%d\n", word, freq[word]
  8934. +      }'
  8935. +    Assuming we have saved this program in a file named `frequency.awk',
  8936. + and that the data is in `file1', the following pipeline
  8937. +      awk -f frequency.awk file1 | sort +1 -nr
  8938. + produces a table of the words appearing in `file1' in order of
  8939. + decreasing frequency.
  8940. +    The `awk' program suitably massages the data and produces a word
  8941. + frequency table, which is not ordered.
  8942. +    The `awk' script's output is then sorted by the `sort' command and
  8943. + printed on the terminal.  The options given to `sort' in this example
  8944. + specify to sort using the second field of each input line (skipping one
  8945. + field), that the sort keys should be treated as numeric quantities
  8946. + (otherwise `15' would come before `5'), and that the sorting should be
  8947. + done in descending (reverse) order.
  8948. +    We could have even done the `sort' from within the program, by
  8949. + changing the `END' action to:
  8950. +      END {
  8951. +          sort = "sort +1 -nr"
  8952. +          for (word in freq)
  8953. +              printf "%s\t%d\n", word, freq[word] | sort
  8954. +          close(sort)
  8955. +      }'
  8956. +    See the general operating system documentation for more information
  8957. + on how to use the `sort' command.
  8958. + 
  8959. + File: gawk.info,  Node: Bugs,  Next: Notes,  Prev: Sample Program,  Up: Top
  8960. + Reporting Problems and Bugs
  8961. + ***************************
  8962. +    If you have problems with `gawk' or think that you have found a bug,
  8963. + please report it to the developers; we cannot promise to do anything
  8964. + but we might well want to fix it.
  8965. +    Before reporting a bug, make sure you have actually found a real bug.
  8966. + Carefully reread the documentation and see if it really says you can do
  8967. + what you're trying to do.  If it's not clear whether you should be able
  8968. + to do something or not, report that too; it's a bug in the
  8969. + documentation!
  8970. +    Before reporting a bug or trying to fix it yourself, try to isolate
  8971. + it to the smallest possible `awk' program and input data file that
  8972. + reproduces the problem.  Then send us the program and data file, some
  8973. + idea of what kind of Unix system you're using, and the exact results
  8974. + `gawk' gave you.  Also say what you expected to occur; this will help
  8975. + us decide whether the problem was really in the documentation.
  8976. +    Once you have a precise problem, send e-mail to (Internet)
  8977. + `bug-gnu-utils@prep.ai.mit.edu' or (UUCP)
  8978. + `mit-eddie!prep.ai.mit.edu!bug-gnu-utils'.  Please include the version
  8979. + number of `gawk' you are using.  You can get this information with the
  8980. + command `gawk -W version '{}' /dev/null'.  You should send carbon
  8981. + copies of your mail to David Trueman at `david@cs.dal.ca', and to
  8982. + Arnold Robbins, who can be reached at `arnold@skeeve.atl.ga.us'.  David
  8983. + is most likely to fix code problems, while Arnold is most likely to fix
  8984. + documentation problems.
  8985. +    Non-bug suggestions are always welcome as well.  If you have
  8986. + questions about things that are unclear in the documentation or are
  8987. + just obscure features, ask Arnold Robbins; he will try to help you out,
  8988. + although he may not have the time to fix the problem.  You can send him
  8989. + electronic mail at the Internet address above.
  8990. +    If you find bugs in one of the non-Unix ports of `gawk', please send
  8991. + an electronic mail message to the person who maintains that port.  They
  8992. + are listed below, and also in the `README' file in the `gawk'
  8993. + distribution.  Information in the `README' file should be considered
  8994. + authoritative if it conflicts with this manual.
  8995. +    The people maintaining the non-Unix ports of `gawk' are:
  8996. + MS-DOS
  8997. +      The port to MS-DOS is maintained by Scott Deifik.  His electronic
  8998. +      mail address is `scottd@amgen.com'.
  8999. + VMS
  9000. +      The port to VAX VMS is maintained by Pat Rankin.  His electronic
  9001. +      mail address is `rankin@eql.caltech.edu'.
  9002. + Atari ST
  9003. +      The port to the Atari ST is maintained by Michal Jaegermann.  His
  9004. +      electronic mail address is `ntomczak@vm.ucs.ualberta.ca'.
  9005. +    If your bug is also reproducible under Unix, please send copies of
  9006. + your report to the general GNU bug list, as well as to Arnold Robbins
  9007. + and David Trueman, at the addresses listed above.
  9008. + 
  9009. + File: gawk.info,  Node: Notes,  Next: Glossary,  Prev: Bugs,  Up: Top
  9010. + Implementation Notes
  9011. + ********************
  9012. +    This appendix contains information mainly of interest to
  9013. + implementors and maintainers of `gawk'.  Everything in it applies
  9014. + specifically to `gawk', and not to other implementations.
  9015. + * Menu:
  9016. + * Compatibility Mode::          How to disable certain `gawk' extensions.
  9017. + * Future Extensions::           New features we may implement soon.
  9018. + * Improvements::                Suggestions for improvements by volunteers.
  9019. + 
  9020. + File: gawk.info,  Node: Compatibility Mode,  Next: Future Extensions,  Prev: Notes,  Up: Notes
  9021. + Downward Compatibility and Debugging
  9022. + ====================================
  9023. +    *Note Extensions in `gawk' not in POSIX `awk': POSIX/GNU, for a
  9024. + summary of the GNU extensions to the `awk' language and program.  All
  9025. + of these features can be turned off by invoking `gawk' with the `-W
  9026. + compat' option, or with the `-W posix' option.
  9027. +    If `gawk' is compiled for debugging with `-DDEBUG', then there is
  9028. + one more option available on the command line:
  9029. + `-W parsedebug'
  9030. +      Print out the parse stack information as the program is being
  9031. +      parsed.
  9032. +    This option is intended only for serious `gawk' developers, and not
  9033. + for the casual user.  It probably has not even been compiled into your
  9034. + version of `gawk', since it slows down execution.
  9035. + 
  9036. + File: gawk.info,  Node: Future Extensions,  Next: Improvements,  Prev: Compatibility Mode,  Up: Notes
  9037. + Probable Future Extensions
  9038. + ==========================
  9039. +    This section briefly lists extensions that indicate the directions
  9040. + we are currently considering for `gawk'.  The file `FUTURES' in the
  9041. + `gawk' distributions lists these extensions, as well as several others.
  9042. + `RS' as a regexp
  9043. +      The meaning of `RS' may be generalized along the lines of `FS'.
  9044. + Control of subprocess environment
  9045. +      Changes made in `gawk' to the array `ENVIRON' may be propagated to
  9046. +      subprocesses run by `gawk'.
  9047. + Databases
  9048. +      It may be possible to map a GDBM/NDBM/SDBM file into an `awk'
  9049. +      array.
  9050. + Single-character fields
  9051. +      The null string, `""', as a field separator, will cause field
  9052. +      splitting and the `split' function to separate individual
  9053. +      characters.  Thus, `split(a, "abcd", "")' would yield `a[1] ==
  9054. +      "a"', `a[2] == "b"', and so on.
  9055. + More `lint' warnings
  9056. +      There are more things that could be checked for portability.
  9057. + `RECLEN' variable for fixed length records
  9058. +      Along with `FIELDWIDTHS', this would speed up the processing of
  9059. +      fixed-length records.
  9060. + `RT' variable to hold the record terminator
  9061. +      It is occasionally useful to have access to the actual string of
  9062. +      characters that matched the `RS' variable.  The `RT' variable
  9063. +      would hold these characters.
  9064. + A `restart' keyword
  9065. +      After modifying `$0', `restart' would restart the pattern matching
  9066. +      loop, without reading a new record from the input.
  9067. + A `|&' redirection
  9068. +      The `|&' redirection, in place of `|', would open a two-way
  9069. +      pipeline for communication with a sub-process (via `getline' and
  9070. +      `print' and `printf').
  9071. + `IGNORECASE' affecting all comparisons
  9072. +      The effects of the `IGNORECASE' variable may be generalized to all
  9073. +      string comparisons, and not just regular expression operations.
  9074. + A way to mix command line source code and library files
  9075. +      There may be a new option that would make it possible to easily
  9076. +      use library functions from a program entered on the command line.
  9077. + GNU-style long options
  9078. +      We will add GNU-style long options to `gawk' for compatibility
  9079. +      with other GNU programs.  (For example, `--field-separator=:'
  9080. +      would be equivalent to `-F:'.)
  9081. + 
  9082. + File: gawk.info,  Node: Improvements,  Prev: Future Extensions,  Up: Notes
  9083. + Suggestions for Improvements
  9084. + ============================
  9085. +    Here are some projects that would-be `gawk' hackers might like to
  9086. + take on.  They vary in size from a few days to a few weeks of
  9087. + programming, depending on which one you choose and how fast a
  9088. + programmer you are.  Please send any improvements you write to the
  9089. + maintainers at the GNU project.
  9090. +   1. Compilation of `awk' programs: `gawk' uses a Bison (YACC-like)
  9091. +      parser to convert the script given it into a syntax tree; the
  9092. +      syntax tree is then executed by a simple recursive evaluator.
  9093. +      This method incurs a lot of overhead, since the recursive
  9094. +      evaluator performs many procedure calls to do even the simplest
  9095. +      things.
  9096. +      It should be possible for `gawk' to convert the script's parse tree
  9097. +      into a C program which the user would then compile, using the
  9098. +      normal C compiler and a special `gawk' library to provide all the
  9099. +      needed functions (regexps, fields, associative arrays, type
  9100. +      coercion, and so on).
  9101. +      An easier possibility might be for an intermediate phase of `awk'
  9102. +      to convert the parse tree into a linear byte code form like the
  9103. +      one used in GNU Emacs Lisp.  The recursive evaluator would then be
  9104. +      replaced by a straight line byte code interpreter that would be
  9105. +      intermediate in speed between running a compiled program and doing
  9106. +      what `gawk' does now.
  9107. +      This may actually happen for the 3.0 version of `gawk'.
  9108. +   2. An error message section has not been included in this version of
  9109. +      the manual.  Perhaps some nice beta testers will document some of
  9110. +      the messages for the future.
  9111. +   3. The programs in the test suite could use documenting in this
  9112. +      manual.
  9113. +   4. The programs and data files in the manual should be available in
  9114. +      separate files to facilitate experimentation.
  9115. +   5. See the `FUTURES' file for more ideas.  Contact us if you would
  9116. +      seriously like to tackle any of the items listed there.
  9117. + 
  9118. + File: gawk.info,  Node: Glossary,  Next: Index,  Prev: Notes,  Up: Top
  9119. + Glossary
  9120. + ********
  9121. + Action
  9122. +      A series of `awk' statements attached to a rule.  If the rule's
  9123. +      pattern matches an input record, the `awk' language executes the
  9124. +      rule's action.  Actions are always enclosed in curly braces.
  9125. +      *Note Overview of Actions: Actions.
  9126. + Amazing `awk' Assembler
  9127. +      Henry Spencer at the University of Toronto wrote a retargetable
  9128. +      assembler completely as `awk' scripts.  It is thousands of lines
  9129. +      long, including machine descriptions for several 8-bit
  9130. +      microcomputers.  It is a good example of a program that would have
  9131. +      been better written in another language.
  9132. + ANSI
  9133. +      The American National Standards Institute.  This organization
  9134. +      produces many standards, among them the standard for the C
  9135. +      programming language.
  9136. + Assignment
  9137. +      An `awk' expression that changes the value of some `awk' variable
  9138. +      or data object.  An object that you can assign to is called an
  9139. +      "lvalue".  *Note Assignment Expressions: Assignment Ops.
  9140. + `awk' Language
  9141. +      The language in which `awk' programs are written.
  9142. + `awk' Program
  9143. +      An `awk' program consists of a series of "patterns" and "actions",
  9144. +      collectively known as "rules".  For each input record given to the
  9145. +      program, the program's rules are all processed in turn.  `awk'
  9146. +      programs may also contain function definitions.
  9147. + `awk' Script
  9148. +      Another name for an `awk' program.
  9149. + Built-in Function
  9150. +      The `awk' language provides built-in functions that perform various
  9151. +      numerical, time stamp related, and string computations.  Examples
  9152. +      are `sqrt' (for the square root of a number) and `substr' (for a
  9153. +      substring of a string).  *Note Built-in Functions: Built-in.
  9154. + Built-in Variable
  9155. +      `ARGC', `ARGIND', `ARGV', `CONVFMT', `ENVIRON', `ERRNO',
  9156. +      `FIELDWIDTHS', `FILENAME', `FNR', `FS', `IGNORECASE', `NF', `NR',
  9157. +      `OFMT', `OFS', `ORS', `RLENGTH', `RSTART', `RS', and `SUBSEP', are
  9158. +      the variables that have special meaning to `awk'.  Changing some
  9159. +      of them affects `awk''s running environment.  *Note Built-in
  9160. +      Variables::.
  9161. + Braces
  9162. +      See "Curly Braces."
  9163. + C
  9164. +      The system programming language that most GNU software is written
  9165. +      in.  The `awk' programming language has C-like syntax, and this
  9166. +      manual points out similarities between `awk' and C when
  9167. +      appropriate.
  9168. + CHEM
  9169. +      A preprocessor for `pic' that reads descriptions of molecules and
  9170. +      produces `pic' input for drawing them.  It was written by Brian
  9171. +      Kernighan, and is available from `netlib@research.att.com'.
  9172. + Compound Statement
  9173. +      A series of `awk' statements, enclosed in curly braces.  Compound
  9174. +      statements may be nested.  *Note Control Statements in Actions:
  9175. +      Statements.
  9176. + Concatenation
  9177. +      Concatenating two strings means sticking them together, one after
  9178. +      another, giving a new string.  For example, the string `foo'
  9179. +      concatenated with the string `bar' gives the string `foobar'.
  9180. +      *Note String Concatenation: Concatenation.
  9181. + Conditional Expression
  9182. +      An expression using the `?:' ternary operator, such as `EXPR1 ?
  9183. +      EXPR2 : EXPR3'.  The expression EXPR1 is evaluated; if the result
  9184. +      is true, the value of the whole expression is the value of EXPR2
  9185. +      otherwise the value is EXPR3.  In either case, only one of EXPR2
  9186. +      and EXPR3 is evaluated.  *Note Conditional Expressions:
  9187. +      Conditional Exp.
  9188. + Constant Regular Expression
  9189. +      A constant regular expression is a regular expression written
  9190. +      within slashes, such as `/foo/'.  This regular expression is chosen
  9191. +      when you write the `awk' program, and cannot be changed doing its
  9192. +      execution.  *Note How to Use Regular Expressions: Regexp Usage.
  9193. + Comparison Expression
  9194. +      A relation that is either true or false, such as `(a < b)'.
  9195. +      Comparison expressions are used in `if', `while', and `for'
  9196. +      statements, and in patterns to select which input records to
  9197. +      process.  *Note Comparison Expressions: Comparison Ops.
  9198. + Curly Braces
  9199. +      The characters `{' and `}'.  Curly braces are used in `awk' for
  9200. +      delimiting actions, compound statements, and function bodies.
  9201. + Data Objects
  9202. +      These are numbers and strings of characters.  Numbers are
  9203. +      converted into strings and vice versa, as needed.  *Note
  9204. +      Conversion of Strings and Numbers: Conversion.
  9205. + Dynamic Regular Expression
  9206. +      A dynamic regular expression is a regular expression written as an
  9207. +      ordinary expression.  It could be a string constant, such as
  9208. +      `"foo"', but it may also be an expression whose value may vary.
  9209. +      *Note How to Use Regular Expressions: Regexp Usage.
  9210. + Escape Sequences
  9211. +      A special sequence of characters used for describing nonprinting
  9212. +      characters, such as `\n' for newline, or `\033' for the ASCII ESC
  9213. +      (escape) character.  *Note Constant Expressions: Constants.
  9214. + Field
  9215. +      When `awk' reads an input record, it splits the record into pieces
  9216. +      separated by whitespace (or by a separator regexp which you can
  9217. +      change by setting the built-in variable `FS').  Such pieces are
  9218. +      called fields.  If the pieces are of fixed length, you can use the
  9219. +      built-in variable `FIELDWIDTHS' to describe their lengths.  *Note
  9220. +      How Input is Split into Records: Records.
  9221. + Format
  9222. +      Format strings are used to control the appearance of output in the
  9223. +      `printf' statement.  Also, data conversions from numbers to strings
  9224. +      are controlled by the format string contained in the built-in
  9225. +      variable `CONVFMT'.  *Note Format-Control Letters: Control Letters.
  9226. + Function
  9227. +      A specialized group of statements often used to encapsulate general
  9228. +      or program-specific tasks.  `awk' has a number of built-in
  9229. +      functions, and also allows you to define your own.  *Note Built-in
  9230. +      Functions: Built-in.  Also, see *Note User-defined Functions:
  9231. +      User-defined.
  9232. + `gawk'
  9233. +      The GNU implementation of `awk'.
  9234. + GNU
  9235. +      "GNU's not Unix".  An on-going project of the Free Software
  9236. +      Foundation to create a complete, freely distributable,
  9237. +      POSIX-compliant computing environment.
  9238. + Input Record
  9239. +      A single chunk of data read in by `awk'.  Usually, an `awk' input
  9240. +      record consists of one line of text.  *Note How Input is Split
  9241. +      into Records: Records.
  9242. + Keyword
  9243. +      In the `awk' language, a keyword is a word that has special
  9244. +      meaning.  Keywords are reserved and may not be used as variable
  9245. +      names.
  9246. +      `awk''s keywords are: `if', `else', `while', `do...while', `for',
  9247. +      `for...in', `break', `continue', `delete', `next', `function',
  9248. +      `func', and `exit'.
  9249. + Lvalue
  9250. +      An expression that can appear on the left side of an assignment
  9251. +      operator.  In most languages, lvalues can be variables or array
  9252. +      elements.  In `awk', a field designator can also be used as an
  9253. +      lvalue.
  9254. + Number
  9255. +      A numeric valued data object.  The `gawk' implementation uses
  9256. +      double precision floating point to represent numbers.
  9257. + Pattern
  9258. +      Patterns tell `awk' which input records are interesting to which
  9259. +      rules.
  9260. +      A pattern is an arbitrary conditional expression against which
  9261. +      input is tested.  If the condition is satisfied, the pattern is
  9262. +      said to "match" the input record.  A typical pattern might compare
  9263. +      the input record against a regular expression.  *Note Patterns::.
  9264. + POSIX
  9265. +      The name for a series of standards being developed by the IEEE
  9266. +      that specify a Portable Operating System interface.  The "IX"
  9267. +      denotes the Unix heritage of these standards.  The main standard
  9268. +      of interest for `awk' users is P1003.2, the Command Language and
  9269. +      Utilities standard.
  9270. + Range (of input lines)
  9271. +      A sequence of consecutive lines from the input file.  A pattern
  9272. +      can specify ranges of input lines for `awk' to process, or it can
  9273. +      specify single lines.  *Note Patterns::.
  9274. + Recursion
  9275. +      When a function calls itself, either directly or indirectly.  If
  9276. +      this isn't clear, refer to the entry for "recursion."
  9277. + Redirection
  9278. +      Redirection means performing input from other than the standard
  9279. +      input stream, or output to other than the standard output stream.
  9280. +      You can redirect the output of the `print' and `printf' statements
  9281. +      to a file or a system command, using the `>', `>>', and `|'
  9282. +      operators.  You can redirect input to the `getline' statement using
  9283. +      the `<' and `|' operators.  *Note Redirecting Output of `print'
  9284. +      and `printf': Redirection.
  9285. + Regular Expression
  9286. +      See "regexp."
  9287. + Regexp
  9288. +      Short for "regular expression".  A regexp is a pattern that
  9289. +      denotes a set of strings, possibly an infinite set.  For example,
  9290. +      the regexp `R.*xp' matches any string starting with the letter `R'
  9291. +      and ending with the letters `xp'.  In `awk', regexps are used in
  9292. +      patterns and in conditional expressions.  Regexps may contain
  9293. +      escape sequences.  *Note Regular Expressions as Patterns: Regexp.
  9294. + Rule
  9295. +      A segment of an `awk' program, that specifies how to process single
  9296. +      input records.  A rule consists of a "pattern" and an "action".
  9297. +      `awk' reads an input record; then, for each rule, if the input
  9298. +      record satisfies the rule's pattern, `awk' executes the rule's
  9299. +      action.  Otherwise, the rule does nothing for that input record.
  9300. + Side Effect
  9301. +      A side effect occurs when an expression has an effect aside from
  9302. +      merely producing a value.  Assignment expressions, increment
  9303. +      expressions and function calls have side effects.  *Note
  9304. +      Assignment Expressions: Assignment Ops.
  9305. + Special File
  9306. +      A file name interpreted internally by `gawk', instead of being
  9307. +      handed directly to the underlying operating system.  For example,
  9308. +      `/dev/stdin'.  *Note Standard I/O Streams: Special Files.
  9309. + Stream Editor
  9310. +      A program that reads records from an input stream and processes
  9311. +      them one or more at a time.  This is in contrast with batch
  9312. +      programs, which may expect to read their input files in entirety
  9313. +      before starting to do anything, and with interactive programs,
  9314. +      which require input from the user.
  9315. + String
  9316. +      A datum consisting of a sequence of characters, such as `I am a
  9317. +      string'.  Constant strings are written with double-quotes in the
  9318. +      `awk' language, and may contain escape sequences.  *Note Constant
  9319. +      Expressions: Constants.
  9320. + Whitespace
  9321. +      A sequence of blank or tab characters occurring inside an input
  9322. +      record or a string.
  9323. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.info-9 gawk-2.15.5/gawk.info-9
  9324. *** /src/baseline/gawk-2.15.5/gawk.info-9    Thu Jan  1 00:00:00 1970
  9325. --- gawk-2.15.5/gawk.info-9    Sun Jun 12 22:28:56 1994
  9326. ***************
  9327. *** 0 ****
  9328. --- 1,359 ----
  9329. + This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  9330. + file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  9331. +    This file documents `awk', a program that you can use to select
  9332. + particular records in a file and perform operations upon them.
  9333. +    This is Edition 0.15 of `The GAWK Manual',
  9334. + for the 2.15 version of the GNU implementation
  9335. + of AWK.
  9336. +    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  9337. +    Permission is granted to make and distribute verbatim copies of this
  9338. + manual provided the copyright notice and this permission notice are
  9339. + preserved on all copies.
  9340. +    Permission is granted to copy and distribute modified versions of
  9341. + this manual under the conditions for verbatim copying, provided that
  9342. + the entire resulting derived work is distributed under the terms of a
  9343. + permission notice identical to this one.
  9344. +    Permission is granted to copy and distribute translations of this
  9345. + manual into another language, under the above conditions for modified
  9346. + versions, except that this permission notice may be stated in a
  9347. + translation approved by the Foundation.
  9348. + 
  9349. + File: gawk.info,  Node: Index,  Prev: Glossary,  Up: Top
  9350. + Index
  9351. + *****
  9352. + * Menu:
  9353. + * $ (field operator):                   Fields.
  9354. + * -assign option:                       Options.
  9355. + * -compat option:                       Options.
  9356. + * -copyleft option:                     Options.
  9357. + * -copyright option:                    Options.
  9358. + * -field-separator option:              Options.
  9359. + * -file option:                         Options.
  9360. + * -help option:                         Options.
  9361. + * -lint option:                         Options.
  9362. + * -posix option:                        Options.
  9363. + * -source option:                       Options.
  9364. + * -usage option:                        Options.
  9365. + * -version option:                      Options.
  9366. + * AWKPATH environment variable:         AWKPATH Variable.
  9367. + * awk language:                         This Manual.
  9368. + * awk program:                          This Manual.
  9369. + * BEGIN special pattern:                BEGIN/END.
  9370. + * break statement:                      Break Statement.
  9371. + * continue statement:                   Continue Statement.
  9372. + * delete statement:                     Delete.
  9373. + * END special pattern:                  BEGIN/END.
  9374. + * exit statement:                       Exit Statement.
  9375. + * for (x in ...):                       Scanning an Array.
  9376. + * for statement:                        For Statement.
  9377. + * if statement:                         If Statement.
  9378. + * next file statement:                  Next File Statement.
  9379. + * next statement:                       Next Statement.
  9380. + * printf statement, syntax of:          Basic Printf.
  9381. + * printf, format-control characters:    Control Letters.
  9382. + * printf, modifiers:                    Format Modifiers.
  9383. + * print statement:                      Print.
  9384. + * return statement:                     Return Statement.
  9385. + * while statement:                      While Statement.
  9386. + * /dev/fd/:                             Special Files.
  9387. + * /dev/pgrpid:                          Special Files.
  9388. + * /dev/pid:                             Special Files.
  9389. + * /dev/ppid:                            Special Files.
  9390. + * /dev/stderr:                          Special Files.
  9391. + * /dev/stdin:                           Special Files.
  9392. + * /dev/stdout:                          Special Files.
  9393. + * /dev/user:                            Special Files.
  9394. + * BBS-list file:                        Sample Data Files.
  9395. + * inventory-shipped file:               Sample Data Files.
  9396. + * #!:                                   Executable Scripts.
  9397. + * #:                                    Comments.
  9398. + * -F option:                            Field Separators.
  9399. + * -f option:                            Long.
  9400. + * -v option:                            Options.
  9401. + * -W option:                            Options.
  9402. + * print $0:                             Very Simple.
  9403. + * accessing fields:                     Fields.
  9404. + * acronym:                              History.
  9405. + * action, curly braces:                 Actions.
  9406. + * action, default:                      Very Simple.
  9407. + * action, definition of:                Actions.
  9408. + * action, separating statements:        Actions.
  9409. + * addition:                             Arithmetic Ops.
  9410. + * and operator:                         Boolean Ops.
  9411. + * anonymous ftp:                        Extracting.
  9412. + * anonymous uucp:                       Extracting.
  9413. + * applications of awk:                  When.
  9414. + * ARGIND:                               Auto-set.
  9415. + * arguments in function call:           Function Calls.
  9416. + * arguments, command line:              Command Line.
  9417. + * ARGV:                                 Other Arguments.
  9418. + * arithmetic operators:                 Arithmetic Ops.
  9419. + * array assignment:                     Assigning Elements.
  9420. + * array reference:                      Reference to Elements.
  9421. + * arrays:                               Array Intro.
  9422. + * arrays, definition of:                Array Intro.
  9423. + * arrays, deleting an element:          Delete.
  9424. + * arrays, multi-dimensional subscripts: Multi-dimensional.
  9425. + * arrays, presence of elements:         Reference to Elements.
  9426. + * arrays, special for statement:        Scanning an Array.
  9427. + * assignment operators:                 Assignment Ops.
  9428. + * assignment to fields:                 Changing Fields.
  9429. + * associative arrays:                   Array Intro.
  9430. + * backslash continuation:               Statements/Lines.
  9431. + * basic function of gawk:               Getting Started.
  9432. + * body of a loop:                       While Statement.
  9433. + * boolean expressions:                  Boolean Ops.
  9434. + * boolean operators:                    Boolean Ops.
  9435. + * boolean patterns:                     Boolean Patterns.
  9436. + * buffering output:                     I/O Functions.
  9437. + * buffers, flushing:                    I/O Functions.
  9438. + * built-in functions:                   Built-in.
  9439. + * built-in variables:                   Built-in Variables.
  9440. + * built-in variables, user modifiable:  User-modified.
  9441. + * call by reference:                    Function Caveats.
  9442. + * call by value:                        Function Caveats.
  9443. + * calling a function:                   Function Calls.
  9444. + * case sensitivity:                     Read Terminal.
  9445. + * changing contents of a field:         Changing Fields.
  9446. + * close:                                Close Input.
  9447. + * close:                                Close Output.
  9448. + * closing input files and pipes:        Close Input.
  9449. + * closing output files and pipes:       Close Output.
  9450. + * command line:                         Command Line.
  9451. + * command line formats:                 Running gawk.
  9452. + * command line, setting FS on:          Field Separators.
  9453. + * comments:                             Comments.
  9454. + * comparison expressions:               Comparison Ops.
  9455. + * comparison expressions as patterns:   Comparison Patterns.
  9456. + * computed regular expressions:         Regexp Usage.
  9457. + * concatenation:                        Concatenation.
  9458. + * conditional expression:               Conditional Exp.
  9459. + * constants, types of:                  Constants.
  9460. + * continuation of lines:                Statements/Lines.
  9461. + * control statement:                    Statements.
  9462. + * conversion of strings and numbers:    Conversion.
  9463. + * conversion of strings and numbers:    Values.
  9464. + * conversions, during subscripting:     Numeric Array Subscripts.
  9465. + * CONVFMT:                              Numeric Array Subscripts.
  9466. + * CONVFMT:                              Comparison Ops.
  9467. + * CONVFMT:                              Conversion.
  9468. + * curly braces:                         Actions.
  9469. + * default action:                       Very Simple.
  9470. + * default pattern:                      Very Simple.
  9471. + * defining functions:                   Definition Syntax.
  9472. + * deleting elements of arrays:          Delete.
  9473. + * deprecated features:                  Obsolete.
  9474. + * deprecated options:                   Obsolete.
  9475. + * differences: gawk and awk:            Getline.
  9476. + * directory search:                     AWKPATH Variable.
  9477. + * division:                             Arithmetic Ops.
  9478. + * documenting awk programs:             Comments.
  9479. + * dynamic regular expressions:          Regexp Usage.
  9480. + * element assignment:                   Assigning Elements.
  9481. + * element of array:                     Reference to Elements.
  9482. + * empty pattern:                        Empty.
  9483. + * ENVIRON:                              Auto-set.
  9484. + * ERRNO:                                Getline.
  9485. + * escape sequence notation:             Constants.
  9486. + * examining fields:                     Fields.
  9487. + * executable scripts:                   Executable Scripts.
  9488. + * explicit input:                       Getline.
  9489. + * exponentiation:                       Arithmetic Ops.
  9490. + * expression:                           Expressions.
  9491. + * expression, conditional:              Conditional Exp.
  9492. + * expressions, assignment:              Assignment Ops.
  9493. + * expressions, boolean:                 Boolean Ops.
  9494. + * expressions, comparison:              Comparison Ops.
  9495. + * field separator, FS:                  Field Separators.
  9496. + * field separator, choice of:           Field Separators.
  9497. + * field separator: on command line:     Field Separators.
  9498. + * field, changing contents of:          Changing Fields.
  9499. + * fields:                               Fields.
  9500. + * fields, separating:                   Field Separators.
  9501. + * file descriptors:                     Special Files.
  9502. + * file, awk program:                    Long.
  9503. + * FILENAME:                             Reading Files.
  9504. + * flushing buffers:                     I/O Functions.
  9505. + * FNR:                                  Records.
  9506. + * format specifier:                     Control Letters.
  9507. + * format string:                        Basic Printf.
  9508. + * formatted output:                     Printf.
  9509. + * FS:                                   Field Separators.
  9510. + * ftp, anonymous:                       Extracting.
  9511. + * function call:                        Function Calls.
  9512. + * function definition:                  Definition Syntax.
  9513. + * functions, user-defined:              User-defined.
  9514. + * getline:                              Getline.
  9515. + * getting gawk:                         Extracting.
  9516. + * gsub:                                 String Functions.
  9517. + * history of awk:                       History.
  9518. + * how awk works:                        Two Rules.
  9519. + * increment operators:                  Increment Ops.
  9520. + * input:                                Reading Files.
  9521. + * input file, sample:                   Sample Data Files.
  9522. + * input redirection:                    Getline.
  9523. + * input, getline command:               Getline.
  9524. + * input, explicit:                      Getline.
  9525. + * input, multiple line records:         Multiple Line.
  9526. + * input, standard:                      Read Terminal.
  9527. + * installation, atari:                  Atari Installation.
  9528. + * installation, ms-dos:                 MS-DOS Installation.
  9529. + * installation, unix:                   Quick Installation.
  9530. + * installation, vms:                    VMS Installation.
  9531. + * interaction, awk and other programs:  I/O Functions.
  9532. + * invocation of gawk:                   Command Line.
  9533. + * language, awk:                        This Manual.
  9534. + * length:                               String Functions.
  9535. + * logical operations:                   Boolean Ops.
  9536. + * long options:                         Command Line.
  9537. + * loop:                                 While Statement.
  9538. + * loops, exiting:                       Break Statement.
  9539. + * lvalue:                               Assignment Ops.
  9540. + * manual, using this:                   This Manual.
  9541. + * match:                                String Functions.
  9542. + * match:                                String Functions.
  9543. + * metacharacters:                       Regexp Operators.
  9544. + * modifiers (in format specifiers):     Format Modifiers.
  9545. + * multi-dimensional subscripts:         Multi-dimensional.
  9546. + * multiple line records:                Multiple Line.
  9547. + * multiple passes over data:            Other Arguments.
  9548. + * multiple statements on one line:      Statements/Lines.
  9549. + * multiplication:                       Arithmetic Ops.
  9550. + * NF:                                   Fields.
  9551. + * not operator:                         Boolean Ops.
  9552. + * NR:                                   Records.
  9553. + * number of fields, NF:                 Fields.
  9554. + * number of records, NR or FNR:         Records.
  9555. + * numbers, used as subscripts:          Numeric Array Subscripts.
  9556. + * numeric constant:                     Constants.
  9557. + * numeric value:                        Constants.
  9558. + * obsolete features:                    Obsolete.
  9559. + * obsolete options:                     Obsolete.
  9560. + * OFMT:                                 Conversion.
  9561. + * OFMT:                                 OFMT.
  9562. + * OFS:                                  Output Separators.
  9563. + * one-liners:                           One-liners.
  9564. + * operator precedence:                  Precedence.
  9565. + * operators, $:                         Fields.
  9566. + * operators, arithmetic:                Arithmetic Ops.
  9567. + * operators, assignment:                Assignment Ops.
  9568. + * operators, boolean:                   Boolean Ops.
  9569. + * operators, increment:                 Increment Ops.
  9570. + * operators, regexp matching:           Regexp Usage.
  9571. + * operators, relational:                Comparison Patterns.
  9572. + * operators, relational:                Comparison Ops.
  9573. + * operators, string:                    Concatenation.
  9574. + * operators, string-matching:           Regexp Usage.
  9575. + * options, command line:                Command Line.
  9576. + * options, long:                        Command Line.
  9577. + * or operator:                          Boolean Ops.
  9578. + * ORS:                                  Output Separators.
  9579. + * output:                               Printing.
  9580. + * output field separator, OFS:          Output Separators.
  9581. + * output record separator, ORS:         Output Separators.
  9582. + * output redirection:                   Redirection.
  9583. + * output, buffering:                    I/O Functions.
  9584. + * output, formatted:                    Printf.
  9585. + * output, piping:                       File/Pipe Redirection.
  9586. + * passes, multiple:                     Other Arguments.
  9587. + * path, search:                         AWKPATH Variable.
  9588. + * pattern, case sensitive:              Read Terminal.
  9589. + * pattern, comparison expressions:      Comparison Patterns.
  9590. + * pattern, default:                     Very Simple.
  9591. + * pattern, definition of:               Patterns.
  9592. + * pattern, empty:                       Empty.
  9593. + * pattern, regular expressions:         Regexp.
  9594. + * patterns, BEGIN:                      BEGIN/END.
  9595. + * patterns, END:                        BEGIN/END.
  9596. + * patterns, boolean:                    Boolean Patterns.
  9597. + * patterns, range:                      Ranges.
  9598. + * patterns, types of:                   Kinds of Patterns.
  9599. + * pipes for output:                     File/Pipe Redirection.
  9600. + * precedence:                           Precedence.
  9601. + * printing:                             Printing.
  9602. + * program file:                         Long.
  9603. + * program, awk:                         This Manual.
  9604. + * program, definition of:               Getting Started.
  9605. + * program, self contained:              Executable Scripts.
  9606. + * programs, documenting:                Comments.
  9607. + * quotient:                             Arithmetic Ops.
  9608. + * range pattern:                        Ranges.
  9609. + * reading files:                        Reading Files.
  9610. + * reading files, getline command:       Getline.
  9611. + * reading files, multiple line records: Multiple Line.
  9612. + * record separator:                     Records.
  9613. + * records, multiple line:               Multiple Line.
  9614. + * redirection of input:                 Getline.
  9615. + * redirection of output:                Redirection.
  9616. + * reference to array:                   Reference to Elements.
  9617. + * regexp:                               Regexp.
  9618. + * regexp as expression:                 Comparison Ops.
  9619. + * regexp operators:                     Comparison Ops.
  9620. + * regexp search operators:              Regexp Usage.
  9621. + * regular expression matching operators: Regexp Usage.
  9622. + * regular expression metacharacters:    Regexp Operators.
  9623. + * regular expressions as field separators: Field Separators.
  9624. + * regular expressions as patterns:      Regexp.
  9625. + * regular expressions, computed:        Regexp Usage.
  9626. + * relational operators:                 Comparison Ops.
  9627. + * relational operators:                 Comparison Patterns.
  9628. + * remainder:                            Arithmetic Ops.
  9629. + * removing elements of arrays:          Delete.
  9630. + * RLENGTH:                              String Functions.
  9631. + * RS:                                   Records.
  9632. + * RSTART:                               String Functions.
  9633. + * rule, definition of:                  Getting Started.
  9634. + * running awk programs:                 Running gawk.
  9635. + * running long programs:                Long.
  9636. + * sample input file:                    Sample Data Files.
  9637. + * scanning an array:                    Scanning an Array.
  9638. + * script, definition of:                Getting Started.
  9639. + * scripts, executable:                  Executable Scripts.
  9640. + * scripts, shell:                       Executable Scripts.
  9641. + * search path:                          AWKPATH Variable.
  9642. + * self contained programs:              Executable Scripts.
  9643. + * shell scripts:                        Executable Scripts.
  9644. + * side effect:                          Assignment Ops.
  9645. + * single quotes, why needed:            One-shot.
  9646. + * split:                                String Functions.
  9647. + * sprintf:                              String Functions.
  9648. + * standard error output:                Special Files.
  9649. + * standard input:                       Read Terminal.
  9650. + * standard input:                       Reading Files.
  9651. + * standard input:                       Special Files.
  9652. + * standard output:                      Special Files.
  9653. + * strftime:                             Time Functions.
  9654. + * string constants:                     Constants.
  9655. + * string operators:                     Concatenation.
  9656. + * string-matching operators:            Regexp Usage.
  9657. + * sub:                                  String Functions.
  9658. + * subscripts in arrays:                 Multi-dimensional.
  9659. + * SUBSEP:                               Multi-dimensional.
  9660. + * substr:                               String Functions.
  9661. + * subtraction:                          Arithmetic Ops.
  9662. + * system:                               I/O Functions.
  9663. + * systime:                              Time Functions.
  9664. + * time of day:                          Time Functions.
  9665. + * time stamps:                          Time Functions.
  9666. + * tolower:                              String Functions.
  9667. + * toupper:                              String Functions.
  9668. + * use of comments:                      Comments.
  9669. + * user-defined functions:               User-defined.
  9670. + * user-defined variables:               Variables.
  9671. + * uses of awk:                          Preface.
  9672. + * using this manual:                    This Manual.
  9673. + * uucp, anonymous:                      Extracting.
  9674. + * variables, user-defined:              Variables.
  9675. + * when to use awk:                      When.
  9676. diff -rc --new-file /src/baseline/gawk-2.15.5/gawk.texi gawk-2.15.5/gawk.texi
  9677. *** /src/baseline/gawk-2.15.5/gawk.texi    Thu May  6 13:37:11 1993
  9678. --- gawk-2.15.5/gawk.texi    Sun Jun 12 21:44:03 1994
  9679. ***************
  9680. *** 7567,7573 ****
  9681.   Here is the @code{awk} version of the @code{date} utility.
  9682.   
  9683.   @smallexample
  9684. ! #! /usr/bin/gawk -f
  9685.   #
  9686.   # date --- implement the P1003.2 Draft 11 'date' command
  9687.   #
  9688. --- 7567,7573 ----
  9689.   Here is the @code{awk} version of the @code{date} utility.
  9690.   
  9691.   @smallexample
  9692. ! #! /bin/gawk -f
  9693.   #
  9694.   # date --- implement the P1003.2 Draft 11 'date' command
  9695.   #
  9696. ***************
  9697. *** 8555,8561 ****
  9698.   separated by colons.  @code{gawk} gets its search path from the
  9699.   @code{AWKPATH} environment variable.  If that variable does not exist,
  9700.   @code{gawk} uses the default path, which is
  9701. ! @samp{.:/usr/lib/awk:/usr/local/lib/awk}.  (Programs written by
  9702.   system administrators should use an @code{AWKPATH} variable that
  9703.   does not include the current directory, @samp{.}.)@refill
  9704.   
  9705. --- 8555,8561 ----
  9706.   separated by colons.  @code{gawk} gets its search path from the
  9707.   @code{AWKPATH} environment variable.  If that variable does not exist,
  9708.   @code{gawk} uses the default path, which is
  9709. ! @samp{.:/local/lib/awk:/gnu/lib/awk}.  (Programs written by
  9710.   system administrators should use an @code{AWKPATH} variable that
  9711.   does not include the current directory, @samp{.}.)@refill
  9712.   
  9713. ***************
  9714. *** 9674,9680 ****
  9715.   The environment variable @code{AWKPATH} specifies a search path to use
  9716.   when finding source files named with the @samp{-f} option.  The default
  9717.   path, which is
  9718. ! @samp{.:/usr/lib/awk:/usr/local/lib/awk} is used if @code{AWKPATH} is not set.
  9719.   If a file name given to the @samp{-f} option contains a @samp{/} character,
  9720.   no path search is performed.
  9721.   @xref{AWKPATH Variable, ,The @code{AWKPATH} Environment Variable},
  9722. --- 9674,9680 ----
  9723.   The environment variable @code{AWKPATH} specifies a search path to use
  9724.   when finding source files named with the @samp{-f} option.  The default
  9725.   path, which is
  9726. ! @samp{.:/local/lib/awk:/gnu/lib/awk} is used if @code{AWKPATH} is not set.
  9727.   If a file name given to the @samp{-f} option contains a @samp{/} character,
  9728.   no path search is performed.
  9729.   @xref{AWKPATH Variable, ,The @code{AWKPATH} Environment Variable},
  9730. diff -rc --new-file /src/baseline/gawk-2.15.5/io.c gawk-2.15.5/io.c
  9731. *** /src/baseline/gawk-2.15.5/io.c    Wed May 11 22:50:41 1994
  9732. --- gawk-2.15.5/io.c    Sun Jun 12 21:44:08 1994
  9733. ***************
  9734. *** 556,563 ****
  9735. --- 556,565 ----
  9736.           status++;
  9737.       }
  9738.       if (fflush(stderr)) {
  9739. + #ifndef __amigados__  /* HACK (fnf) */
  9740.           warning("error writing standard error (%s).", strerror(errno));
  9741.           status++;
  9742. + #endif
  9743.       }
  9744.       for (rp = red_head; rp != NULL; rp = rp->next)
  9745.           /* flush both files and pipes, what the heck */
  9746. ***************
  9747. *** 598,605 ****
  9748. --- 600,609 ----
  9749.           status++;
  9750.       }
  9751.       if (fflush(stderr)) {
  9752. + #ifndef __amigados__  /* HACK (fnf) */
  9753.           warning("error writing standard error (%s).", strerror(errno));
  9754.           status++;
  9755. + #endif
  9756.       }
  9757.       return status;
  9758.   }
  9759. ***************
  9760. *** 909,915 ****
  9761.   wait_any(interesting)
  9762.   int interesting;    /* pid of interest, if any */
  9763.   {
  9764. !     SIGTYPE (*hstat)(), (*istat)(), (*qstat)();
  9765.       int pid;
  9766.       int status = 0;
  9767.       struct redirect *redp;
  9768. --- 913,919 ----
  9769.   wait_any(interesting)
  9770.   int interesting;    /* pid of interest, if any */
  9771.   {
  9772. !     RETSIGTYPE (*hstat)(), (*istat)(), (*qstat)();
  9773.       int pid;
  9774.       int status = 0;
  9775.       struct redirect *redp;
  9776. diff -rc --new-file /src/baseline/gawk-2.15.5/main.c gawk-2.15.5/main.c
  9777. *** /src/baseline/gawk-2.15.5/main.c    Sun May  1 18:38:49 1994
  9778. --- gawk-2.15.5/main.c    Sun Jun 12 21:44:12 1994
  9779. ***************
  9780. *** 33,39 ****
  9781.   static void init_args P((int argc0, int argc, char *argv0, char **argv));
  9782.   static void init_vars P((void));
  9783.   static void pre_assign P((char *v));
  9784. ! SIGTYPE catchsig P((int sig, int code));
  9785.   static void gawk_option P((char *optstr));
  9786.   static void nostalgia P((void));
  9787.   static void version P((void));
  9788. --- 33,39 ----
  9789.   static void init_args P((int argc0, int argc, char *argv0, char **argv));
  9790.   static void init_vars P((void));
  9791.   static void pre_assign P((char *v));
  9792. ! RETSIGTYPE catchsig P((int sig, int code));
  9793.   static void gawk_option P((char *optstr));
  9794.   static void nostalgia P((void));
  9795.   static void version P((void));
  9796. ***************
  9797. *** 148,157 ****
  9798.       setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
  9799.   #endif
  9800.   
  9801. !     (void) signal(SIGFPE,  (SIGTYPE (*) P((int))) catchsig);
  9802. !     (void) signal(SIGSEGV, (SIGTYPE (*) P((int))) catchsig);
  9803.   #ifdef SIGBUS
  9804. !     (void) signal(SIGBUS,  (SIGTYPE (*) P((int))) catchsig);
  9805.   #endif
  9806.   
  9807.       myname = gawk_name(argv[0]);
  9808. --- 148,157 ----
  9809.       setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
  9810.   #endif
  9811.   
  9812. !     (void) signal(SIGFPE,  (RETSIGTYPE (*) P((int))) catchsig);
  9813. !     (void) signal(SIGSEGV, (RETSIGTYPE (*) P((int))) catchsig);
  9814.   #ifdef SIGBUS
  9815. !     (void) signal(SIGBUS,  (RETSIGTYPE (*) P((int))) catchsig);
  9816.   #endif
  9817.   
  9818.       myname = gawk_name(argv[0]);
  9819. ***************
  9820. *** 628,634 ****
  9821.       }
  9822.   }
  9823.   
  9824. ! SIGTYPE
  9825.   catchsig(sig, code)
  9826.   int sig, code;
  9827.   {
  9828. --- 628,634 ----
  9829.       }
  9830.   }
  9831.   
  9832. ! RETSIGTYPE
  9833.   catchsig(sig, code)
  9834.   int sig, code;
  9835.   {
  9836. diff -rc --new-file /src/baseline/gawk-2.15.5/pc/config.h gawk-2.15.5/pc/config.h
  9837. *** /src/baseline/gawk-2.15.5/pc/config.h    Wed Dec 29 11:44:38 1993
  9838. --- gawk-2.15.5/pc/config.h    Sun Jun 12 21:44:14 1994
  9839. ***************
  9840. *** 258,264 ****
  9841.    * this.
  9842.    */
  9843.   
  9844. ! /* #define DEFPATH    ".:/usr/lib/awk:/usr/local/lib/awk" */
  9845.   /* #define ENVSEP    ':' */
  9846.   #define ENVSEP    ';'
  9847.   
  9848. --- 258,264 ----
  9849.    * this.
  9850.    */
  9851.   
  9852. ! /* #define DEFPATH    ".:/local/lib/awk:/gnu/lib/awk" */
  9853.   /* #define ENVSEP    ':' */
  9854.   #define ENVSEP    ';'
  9855.   
  9856. diff -rc --new-file /src/baseline/gawk-2.15.5/protos.h gawk-2.15.5/protos.h
  9857. *** /src/baseline/gawk-2.15.5/protos.h    Sun May  1 18:20:21 1994
  9858. --- gawk-2.15.5/protos.h    Sun Jun 12 22:08:10 1994
  9859. ***************
  9860. *** 69,75 ****
  9861. --- 69,77 ----
  9862.   extern int fprintf P((FILE *, const char *, ...));
  9863.   #if !defined(MSDOS) && !defined(__GNU_LIBRARY__)
  9864.   #ifdef __STDC__
  9865. + #ifndef __amigados__    /* HACK - conflicts with stdio.h - FIXME */
  9866.   extern size_t fwrite P((const aptr_t, size_t, size_t, FILE *));
  9867. + #endif
  9868.   #else
  9869.   extern int fwrite();
  9870.   #endif
  9871. ***************
  9872. *** 84,90 ****
  9873.   extern int isatty P((int));
  9874.   extern void exit P((int));
  9875.   extern int system P((const char *));
  9876. ! extern int sscanf P((const char *, const char *, ...));
  9877.   #ifndef toupper
  9878.   extern int toupper P((int));
  9879.   #endif
  9880. --- 86,92 ----
  9881.   extern int isatty P((int));
  9882.   extern void exit P((int));
  9883.   extern int system P((const char *));
  9884. ! /* extern int sscanf P((const char *, const char *, ...)); */
  9885.   #ifndef toupper
  9886.   extern int toupper P((int));
  9887.   #endif
  9888. diff -rc --new-file /src/baseline/gawk-2.15.5/test/Makefile gawk-2.15.5/test/Makefile
  9889. *** /src/baseline/gawk-2.15.5/test/Makefile    Tue May 10 22:57:41 1994
  9890. --- gawk-2.15.5/test/Makefile    Sun Jun 12 21:49:01 1994
  9891. ***************
  9892. *** 1,4 ****
  9893. --- 1,6 ----
  9894.   SHELL = /bin/sh
  9895. + #COMPARE = cmp
  9896. + COMPARE = diff
  9897.   
  9898.   bigtest:    basic poundbang gawk.extensions
  9899.   
  9900. ***************
  9901. *** 14,20 ****
  9902.   poundbang::
  9903.       cp ../gawk /tmp && chmod +x poundbang && ./poundbang poundbang >tmp
  9904.       rm -f /tmp/gawk
  9905. !     cmp poundbang.good tmp && rm -f tmp
  9906.   
  9907.   msg::
  9908.       @echo 'Any output from "cmp" is bad news, although some differences'
  9909. --- 16,22 ----
  9910.   poundbang::
  9911.       cp ../gawk /tmp && chmod +x poundbang && ./poundbang poundbang >tmp
  9912.       rm -f /tmp/gawk
  9913. !     -$(COMPARE) poundbang.good tmp && rm -f tmp
  9914.   
  9915.   msg::
  9916.       @echo 'Any output from "cmp" is bad news, although some differences'
  9917. ***************
  9918. *** 24,30 ****
  9919.   
  9920.   swaplns::
  9921.       @../gawk -f swaplns.awk data >tmp
  9922. !     cmp swaplns.good tmp && rm -f tmp
  9923.   
  9924.   messages::
  9925.       @../gawk -f messages.awk >out2 2>out3
  9926. --- 26,32 ----
  9927.   
  9928.   swaplns::
  9929.       @../gawk -f swaplns.awk data >tmp
  9930. !     -$(COMPARE) swaplns.good tmp && rm -f tmp
  9931.   
  9932.   messages::
  9933.       @../gawk -f messages.awk >out2 2>out3
  9934. ***************
  9935. *** 32,62 ****
  9936.   
  9937.   argarray::
  9938.       @TEST=test echo just a test | ../gawk -f argarray.awk argarray.awk - >tmp
  9939. !     cmp argarray.good tmp && rm -f tmp
  9940.   
  9941.   fstabplus::
  9942.       @echo '1        2' | ../gawk -f fstabplus >tmp
  9943. !     cmp fstabplus.good tmp && rm -f tmp
  9944.   
  9945.   fsrs::
  9946.       @../gawk -f fsrs.awk fsrs.in >tmp
  9947. !     cmp fsrs.good tmp && rm -f tmp
  9948.   
  9949.   igncfs::
  9950.       @../gawk -f igncfs.awk igncfs.in >tmp
  9951. !     cmp igncfs.good tmp && rm -f tmp
  9952.   
  9953.   longwrds::
  9954.       @../gawk -f longwrds.awk manpage | sort >tmp
  9955. !     cmp longwrds.good tmp && rm -f tmp
  9956.   
  9957.   fieldwdth::
  9958.       @echo '123456789' | ../gawk -v FIELDWIDTHS="2 3 4" '{ print $$2}' >tmp
  9959. !     cmp fieldwdth.good tmp && rm -f tmp
  9960.   
  9961.   ignrcase::
  9962.       @echo xYz | ../gawk -v IGNORECASE=1 '{ sub(/y/, ""); print}' >tmp
  9963. !     cmp ignrcase.good tmp && rm -f tmp
  9964.   
  9965.   regtest::
  9966.       @echo 'Some of the output from regtest is very system specific, do not'
  9967. --- 34,64 ----
  9968.   
  9969.   argarray::
  9970.       @TEST=test echo just a test | ../gawk -f argarray.awk argarray.awk - >tmp
  9971. !     -$(COMPARE) argarray.good tmp && rm -f tmp
  9972.   
  9973.   fstabplus::
  9974.       @echo '1        2' | ../gawk -f fstabplus >tmp
  9975. !     -$(COMPARE) fstabplus.good tmp && rm -f tmp
  9976.   
  9977.   fsrs::
  9978.       @../gawk -f fsrs.awk fsrs.in >tmp
  9979. !     -$(COMPARE) fsrs.good tmp && rm -f tmp
  9980.   
  9981.   igncfs::
  9982.       @../gawk -f igncfs.awk igncfs.in >tmp
  9983. !     -$(COMPARE) igncfs.good tmp && rm -f tmp
  9984.   
  9985.   longwrds::
  9986.       @../gawk -f longwrds.awk manpage | sort >tmp
  9987. !     -$(COMPARE) longwrds.good tmp && rm -f tmp
  9988.   
  9989.   fieldwdth::
  9990.       @echo '123456789' | ../gawk -v FIELDWIDTHS="2 3 4" '{ print $$2}' >tmp
  9991. !     -$(COMPARE) fieldwdth.good tmp && rm -f tmp
  9992.   
  9993.   ignrcase::
  9994.       @echo xYz | ../gawk -v IGNORECASE=1 '{ sub(/y/, ""); print}' >tmp
  9995. !     -$(COMPARE) ignrcase.good tmp && rm -f tmp
  9996.   
  9997.   regtest::
  9998.       @echo 'Some of the output from regtest is very system specific, do not'
  9999. ***************
  10000. *** 66,72 ****
  10001.   
  10002.   posix::
  10003.       @echo '1:2,3 4' | ../gawk -f posix >tmp
  10004. !     cmp posix.good tmp && rm -f tmp
  10005.   
  10006.   manyfiles::
  10007.       @rm -rf junk
  10008. --- 68,74 ----
  10009.   
  10010.   posix::
  10011.       @echo '1:2,3 4' | ../gawk -f posix >tmp
  10012. !     -$(COMPARE) posix.good tmp && rm -f tmp
  10013.   
  10014.   manyfiles::
  10015.       @rm -rf junk
  10016. ***************
  10017. *** 79,106 ****
  10018.   
  10019.   compare::
  10020.       @../gawk -f compare.awk 0 1 compare.in >tmp
  10021. !     cmp compare.good tmp && rm -f tmp
  10022.   
  10023.   arrayref::
  10024.       @../gawk -f arrayref >tmp
  10025. !     cmp arrayref.good tmp && rm -f tmp
  10026.   
  10027.   rs::
  10028.       @../gawk -v RS="" '{ print $$1, $$2}' rs.data >tmp
  10029. !     cmp rs.good tmp && rm -f tmp
  10030.   
  10031.   fsbs::
  10032.       @../gawk -v FS='\' '{ print $$1, $$2 }' fsbs.in >tmp
  10033. !     cmp fsbs.good tmp && rm -f tmp
  10034.   
  10035.   inftest::
  10036.       @echo This test is very machine specific...
  10037.       @../gawk -f inftest.awk >tmp
  10038. !     cmp inftest.good tmp && rm -f tmp
  10039.   
  10040.   getline::
  10041.       @../gawk -f getline.awk getline.awk getline.awk >tmp
  10042. !     cmp getline.good tmp && rm -f tmp
  10043.   
  10044.   rand::
  10045.       @echo The following line should just be 19 random numbers between 1 and 100
  10046. --- 81,108 ----
  10047.   
  10048.   compare::
  10049.       @../gawk -f compare.awk 0 1 compare.in >tmp
  10050. !     -$(COMPARE) compare.good tmp && rm -f tmp
  10051.   
  10052.   arrayref::
  10053.       @../gawk -f arrayref >tmp
  10054. !     -$(COMPARE) arrayref.good tmp && rm -f tmp
  10055.   
  10056.   rs::
  10057.       @../gawk -v RS="" '{ print $$1, $$2}' rs.data >tmp
  10058. !     -$(COMPARE) rs.good tmp && rm -f tmp
  10059.   
  10060.   fsbs::
  10061.       @../gawk -v FS='\' '{ print $$1, $$2 }' fsbs.in >tmp
  10062. !     -$(COMPARE) fsbs.good tmp && rm -f tmp
  10063.   
  10064.   inftest::
  10065.       @echo This test is very machine specific...
  10066.       @../gawk -f inftest.awk >tmp
  10067. !     -$(COMPARE) inftest.good tmp && rm -f tmp
  10068.   
  10069.   getline::
  10070.       @../gawk -f getline.awk getline.awk getline.awk >tmp
  10071. !     -$(COMPARE) getline.good tmp && rm -f tmp
  10072.   
  10073.   rand::
  10074.       @echo The following line should just be 19 random numbers between 1 and 100
  10075. ***************
  10076. *** 123,130 ****
  10077.       cmp splitargv.good tmp && rm -f tmp
  10078.   
  10079.   awkpath::
  10080. !     @AWKPATH=".:lib" ../gawk -f awkpath.awk >tmp
  10081. !     cmp awkpath.good tmp && rm -f tmp
  10082.   
  10083.   nfset::
  10084.       @../gawk -f nfset.awk nfset.in >tmp
  10085. --- 125,132 ----
  10086.       cmp splitargv.good tmp && rm -f tmp
  10087.   
  10088.   awkpath::
  10089. ! #    @AWKPATH=".:lib" ../gawk -f awkpath.awk >tmp
  10090. ! #    cmp awkpath.good tmp && rm -f tmp
  10091.   
  10092.   nfset::
  10093.       @../gawk -f nfset.awk nfset.in >tmp
  10094. diff -rc --new-file /src/baseline/gawk-2.15.5/test/poundbang gawk-2.15.5/test/poundbang
  10095. *** /src/baseline/gawk-2.15.5/test/poundbang    Tue Oct 19 20:07:58 1993
  10096. --- gawk-2.15.5/test/poundbang    Sun Jun 12 21:44:24 1994
  10097. ***************
  10098. *** 1,3 ****
  10099. ! #! /tmp/gawk -f 
  10100.       { ccount += length($0) }
  10101.   END { printf "average line length is %2.4f\n", ccount/NR}
  10102. --- 1,3 ----
  10103. ! #!/tmp/gawk -f 
  10104.       { ccount += length($0) }
  10105.   END { printf "average line length is %2.4f\n", ccount/NR}
  10106.