Home Explore Blog CI



man-pages

14th chunk of `awk.man`
8ee5020dbbbc86d07778ec3e353d600c5b840cff18aa8bba0000000100000ec0
 on non‐escape characters while the AWK book advocates \c be recognized as c which necessitates
       the  double  escaping  of meta‐characters in strings.  POSIX explicitly declines to define the behavior which passively forces programs that must run under a variety of awks to use the more portable but less readable,
       double escape.

       POSIX AWK does not recognize "/dev/std{in,out,err}".  Some systems provide an actual device for this, allowing AWKs which do not implement the feature directly to support it.

       POSIX AWK does not recognize \x hex escape sequences in strings.  Unlike ANSI C, mawk limits the number of digits that follows \x to two as the current implementation only supports 8 bit characters.

       POSIX explicitly leaves the behavior of FS = "" undefined, and mentions splitting the record into characters as a possible interpretation, but currently this use is not portable across implementations.

       Some features were not part of the POSIX standard until long after their introduction in mawk and other implementations.  These have been approved, though still (as of July 2020), are not part of a published standard:

       •   The built‐in fflush first appeared in a 1993 AT&T awk released to netlib.  It was approved for the POSIX standard in 2012.

       •   Aggregate deletion with delete array was approved in 2018.

   Random numbers
       POSIX does not prescribe a method for initializing random numbers at startup.

       In practice, most implementations do nothing special, which makes srand and rand follow the C runtime library, making the initial seed value 1.  Some implementations (Solaris XPG4 and Tru64) return 0  from  the  first
       call to srand, although the results from rand behave as if the initial seed is 1.  Other implementations return 1.

       While mawk can call srand at startup with no parameter (initializing random numbers from the clock), this feature may be suppressed using conditional compilation.

   Extensions added for compatibility for GAWK and BWK
       Nextfile is a gawk extension (also implemented by BWK awk).  It was approved for the POSIX standard in September 2012, and is expected to be part of the next revision of the standard.

       Mktime, strftime and systime are gawk extensions.

       The "/dev/stdin" feature was added to mawk after 1.3.4, for compatibility with gawk and BWK awk.  The corresponding "‐" (alias for /dev/stdin) was present in mawk 1.3.3.

       Interval expressions, e.g., a range {m,n} in Extended Regular Expressions (EREs), were not supported in awk (or even the original “nawk”):

       •   Gawk provided this feature in 1991 (and later, in 1998, options for turning it off, for compatibility with “traditional awk”).

       •   Interval expressions, were introduced into awk regular expressions in IEEE 1003.1‐2001 (also known as Unix 03), along with some internationalization features.

       •   Apple modified its copy of the original awk in April 2006, making this version of awk support interval expressions.

           The updated source provides for compatibility with older “legacy” versions using an environment variable, making this “Unix 2003” feature (perhaps meant as Unix 03) the default.

       •   NetBSD developers copied this change in January 2018, omitting the compatibility option, and then applied it to BWK awk.

       •   The interval expression implementation in mawk is based on changes proposed by James Parkinson in April 2016.

       Mawk also recognizes a few gawk‐specific command line options for script compatibility:

            --help, --posix, -r, --re-interval, --traditional, --version

   Subtle Differences not in POSIX or the AWK Book
 

Title: MAWK's Extensions, Random Numbers, and Subtle Differences from POSIX AWK
Summary
This section covers further compatibility issues between MAWK and POSIX AWK, including handling escape sequences, recognizing special device files, and the behavior of FS = "". It notes features like fflush and aggregate deletion that were introduced in MAWK and later approved for POSIX. The section also discusses the initialization of random numbers, highlighting differences across implementations. It describes extensions added to MAWK for compatibility with GAWK and BWK, such as Nextfile, Mktime, strftime, systime, /dev/stdin, and interval expressions in regular expressions. Finally, it lists several GAWK-specific command-line options that MAWK recognizes for script compatibility and previews that more subtle differences not covered by POSIX or the AWK book will be discussed.