Home Explore Blog CI



man-pages

8th chunk of `awk.man`
25527ca74ee34b91fb4f105777ef446d8d527c927de9f7780000000100000fba
 of the year starting at 1

                   DD the day of the month starting at 1

                   HH hour (0‐23)

                   MM minute (0‐59)

                   SS seconds (0‐59)

                   DST
                      tells how to treat timezone versus daylight savings time:

                        positive
                           DST is in effect

                        zero (default)
                           DST is not in effect

                        negative
                           mktime() should (use timezone information and system databases to) attempt  to determine whether DST is in effect at the specified time.

            strftime([format [, timestamp [, utc ]]])
                   formats the given timestamp using the format (passed to the C strftime function):

                   •   If the format parameter is missing, "%c" is used.

                   •   If the timestamp parameter is missing, the current value from systime is used.

                   •   If the utc parameter is present and nonzero, the result is in UTC.  Otherwise local time is used.

            systime()
                   returns the current time of day as the number of seconds since the Epoch (1970‐01‐01 00:00:00 UTC on POSIX systems).

       Arithmetic functions

            atan2(y,x)
                   Arctan of y/x between -pi and pi.

            cos(x) Cosine function, x in radians.

            exp(x) Exponential function.

            int(x) Returns x truncated towards zero.

            log(x) Natural logarithm.

            rand() Returns a random number between zero and one.

            sin(x) Sine function, x in radians.

            sqrt(x)
                   Returns square root of x.

            srand(expr)

            srand()
                   Seeds the random number generator, using the clock if expr is omitted, and returns the value of the previous seed.  Srand(expr) is useful for repeating pseudo random sequences.

                   Note: mawk is normally configured to seed the random number generator from the clock at startup, making it unnecessary to call srand().  This feature can be suppressed via conditional compile, or  overrid‐
                   den using the -Wrandom option.

   9. Input and output
       There are two output statements, print and printf.

            print  writes $0  ORS to standard output.

            print expr1, expr2, ..., exprn
                   writes expr1 OFS expr2 OFS ... exprn ORS to standard output.  Numeric expressions are converted to string with OFMT.

            printf format, expr‐list
                   duplicates  the  printf  C library function writing to standard output.  The complete ANSI C format specifications are recognized with conversions %c, %d, %e, %E, %f, %g, %G, %i, %o, %s, %u, %x, %X and %%,
                   and conversion qualifiers h and l.

       The argument list to print or printf can optionally be enclosed in parentheses.  Print formats numbers using OFMT or "%d" for exact integers.  "%c" with a numeric argument prints the  corresponding  8  bit  character,
       with  a  string argument it prints the first character of the string.  The output of print and printf can be redirected to a file or command by appending > file, >> file or | command to the end of the print statement.
       Redirection opens file or command only once, subsequent redirections append to the already open stream.  By convention, mawk associates the filename

          •   "/dev/stderr" with stderr,

          •   "/dev/stdout" with stdout,

          •   "-" and "/dev/stdin" with stdin.

       The association with stderr is especially useful because it allows print and printf to be redirected to stderr.  These names can also be passed to functions.

       The input function getline has the following variations.

            getline
                   reads into $0, updates the fields, NF, NR and FNR.

            getline < file
         

Title: AWK Time, Arithmetic Functions, and Input/Output
Summary
This section continues the discussion of AWK's built-in functions, focusing on time and arithmetic. The time functions `strftime` (formatting timestamps) and `systime` (returning current time in seconds since the Epoch) are detailed. It also covers arithmetic functions such as `atan2`, `cos`, `exp`, `int`, `log`, `rand`, `sin`, `sqrt`, and `srand`. Finally, the section outlines input and output functionalities, including `print` and `printf` statements, redirection options, and the special file associations for standard input, output, and error streams. The `getline` function is introduced as well.