MAWK-CODE(7)

๐Ÿ“ฆ
version 1.3.4.20260302 ยท 2 versions
, in alpine 3.23, alpine 3.24, debian trixie, epel 10, epel 9, fedora 43, fedora 44, ubuntu questing, ubuntu resolute, ubuntu stonking

๐ŸŽ€ MAWK-CODE(7) ๐ŸŽ€

mawk-code ยท Miscellaneous section ๐Ÿ’–

โœจ NAME โœจ

mawk-code โ€” dumping mawk's byte-code ๐Ÿงš

๐ŸŒธ SYNOPSIS ๐ŸŒธ

okay so at startup, mawk compiles your script into byte-code ๐Ÿค“ and then it interprets that compiled byte-code. if you wanna peek at it, use the -Wdump option ๐Ÿ‘€

๐Ÿ’œ PROGRAM CODES ๐Ÿ’œ

okay bestie, so while mawk is running your program, it keeps a reference to the command it's currently on in cdp ๐Ÿซถ. after that, there might be data and/or references sitting in cdp[0], cdp[1], etc. โœจ

when an operation needs operands, mawk pushes the values (or array/string references) onto the stack, which updates the stack pointer sp ๐Ÿ“š. once the operation is done, mawk eats those entries off the stack and pushes the result (if there is one) back on ๐Ÿ’….

and while it's running user-defined functions, mawk keeps a frame pointer fp so it can find the function's local variables ๐Ÿฆ‹.

๐ŸŒธ a_cat ๐ŸŒธ

Concatenate array-indices ๐Ÿ”—

Usage:

Forms a multiple array index by concatenating the elements of
sp[1-cnt..0], with each element separated by SUBSEP.

Parameters:

  • cdp[0] โ€” the cnt (how many elements to concatenate) comes right after the command ๐Ÿ”ข
  • sp[0]..sp[1-cnt] โ€” hold references to the elements to concatenate ๐Ÿงธ

It returns the index in sp[0] โœจ

๐Ÿฆ‹ a_del ๐Ÿฆ‹

Delete an array item ๐Ÿ—‘๏ธ

Usage:

delete array[expr]

Parameters:

  • sp[0] โ€” points to the array ๐Ÿ“ฆ
  • sp[-1] โ€” is an expr ๐Ÿ’ญ

๐Ÿ“ a_length ๐Ÿ“

Find the length of an array ๐Ÿ“

Usage:

length(array)

Parameters:

  • sp[0] โ€” points to the array ๐Ÿ“ฆ

It returns the length of the array in sp[0] ๐Ÿ’–

๐ŸŒˆ a_pusha ๐ŸŒˆ

Push the array address onto the stack ๐Ÿš€

Usage:

This is used to set up a calling argument for a function.

Parameters:

  • cdp[0] โ€” the array reference follows the command ๐ŸŽ€

It returns the array in sp[0] ๐Ÿ’…

๐Ÿ’œ a_test ๐Ÿ’œ

Test if an expression is present in an array ๐Ÿ”

Usage:

(expression in array)

Parameters:

  • sp[0] โ€” points to an array ๐Ÿ“ฆ
  • sp[-1] โ€” is an expression ๐Ÿ’ญ

It returns 1 in sp[0] if the expression is found, 0 otherwise ๐Ÿซถ

โž• add โž•

Add two numbers ๐Ÿงฎ

Usage:

first + second

Parameters:

  • sp[0] โ€” holds the second value ๐Ÿฅˆ
  • sp[-1] โ€” holds the first value ๐Ÿฅ‡

It returns the sum in sp[0] โœจ

๐Ÿ’ž add_asg ๐Ÿ’ž

Combined addition/assignment ๐Ÿ’•

Usage:

target += source

Parameters:

  • sp[0] โ€” is the source expression ๐Ÿ“ฅ
  • sp[-1] โ€” points to the target ๐ŸŽฏ

It stores the sum in the target, and leaves sp[0] pointing to the target ๐Ÿ’–

๐Ÿงš ae_pusha ๐Ÿงš

Push a reference to an array cell, given an expression for its index ๐Ÿ”Ž

Usage:

arrayname[expression]

Parameters:

  • cdp[0] โ€” an array reference follows the command ๐ŸŽ€
  • sp[0] โ€” has an expression, used for the index of a cell in the array ๐Ÿ—๏ธ

It returns a reference to the addressed cell in sp[0] ๐Ÿ’…

๐Ÿซง ae_pushi ๐Ÿซง

Push the contents of an array cell, given an expression for its index ๐Ÿ“–

Usage:

arrayname[expression]

Parameters:

  • sp[0] โ€” has an expression, used for the index of a cell in the array ๐Ÿ—๏ธ

It returns the contents of the addressed cell in sp[0] ๐ŸŒธ

๐Ÿ” aloop ๐Ÿ”

Update the reference to the next cell for an array loop ๐ŸŒ€

Usage:

for ( i in arrayname )  statement

Parameters:

  • none ๐Ÿ™ˆ

mawk keeps a stack of array-loop state ๐Ÿ“š. it updates the array/cell references in the current loop's state ๐Ÿ’ซ.

๐Ÿ–Š๏ธ assign ๐Ÿ–Š๏ธ

Assigns a value ๐Ÿ“

Usage:

target = source

Parameters:

  • sp[0] โ€” is the source expression ๐Ÿ“ฅ
  • sp[-1] โ€” points to the target ๐ŸŽฏ
  • Stores the sum in the target, leaving sp[0] pointing to the target. ๐Ÿ™ƒ

๐Ÿ“ atan2 ๐Ÿ“

Compute the arc-tangent of two values ๐ŸŒ™

Usage:

atan2( first, second )

Parameters:

  • sp[0] โ€” holds the second value ๐Ÿฅˆ
  • sp[-1] โ€” holds the first value ๐Ÿฅ‡

It returns the result in sp[0] โœจ

๐Ÿ“ž call ๐Ÿ“ž

Call a function ๐Ÿ“ฃ

Usage:

function()

Parameters:

  • cdp[0] โ€” is a reference to the function block ๐Ÿงฑ
  • cdp[1] โ€” holds the number of input arguments ๐Ÿ”ข

It returns the function value in sp[0] ๐ŸŽ

๐Ÿพ cat ๐Ÿพ

Concatenate two strings ๐Ÿงต

Usage:

first second

Parameters:

  • sp[0] โ€” is the second string ๐Ÿฅˆ
  • sp[-1] โ€” is the first string ๐Ÿฅ‡

It returns the result in sp[0] ๐Ÿ’–

๐Ÿšช close ๐Ÿšช

Close the file or pipe associated with an expression ๐Ÿ”’

Usage:

close( expression )

Parameters:

  • sp[0] โ€” holds the expression identifying the file to close ๐Ÿ—‚๏ธ

It returns the status from closing the file: 0 on success or -1 on failure ๐Ÿฅน

๐ŸŒ™ cos ๐ŸŒ™

Compute the cosine of a value in radians ๐ŸŒŠ

Usage:

cos( value )

Parameters:

  • sp[0] โ€” is the value ๐Ÿ”ข

It returns the result in sp[0] โœจ

๐Ÿ—‘๏ธ del_a ๐Ÿ—‘๏ธ

Delete an array ๐Ÿ’…

Usage:

delete(array)

Parameters:

  • sp[0] โ€” is the array to delete ๐Ÿ“ฆ

โž— div โž—

Divide one number by another ๐Ÿฐ

Usage:

first / second

Parameters:

  • sp[0] โ€” is the second value ๐Ÿฅˆ
  • sp[-1] โ€” is the first value ๐Ÿฅ‡

It returns the quotient in sp[0] ๐Ÿ’ซ

๐Ÿซถ div_asg ๐Ÿซถ

Combined division/assignment โž—๐Ÿ’•

Usage:

target /= source

Parameters:

  • sp[0] โ€” is the source ๐Ÿ“ฅ
  • sp[-1] โ€” points to the target ๐ŸŽฏ

It stores the quotient in the target, and leaves sp[0] pointing to the target ๐Ÿ’–

๐ŸŸฐ eq ๐ŸŸฐ

Compare two values ๐Ÿ‘ฏ

Usage:

first == second

Parameters:

  • sp[0] โ€” is the second value ๐Ÿฅˆ
  • sp[-1] โ€” is the first value ๐Ÿฅ‡

It returns 1 in sp[0] if the values are equal, otherwise 0 ๐Ÿซง

๐Ÿ›‘ exit ๐Ÿ›‘

Exits mawk with a specific exit-code ๐Ÿšจ

Usage:

exit(exit_code)

Parameters:

  • sp[0] โ€” is the exit_code ๐Ÿ”ข

โœ… exit0 โœ…

Exits mawk with success ๐Ÿฅณ

Usage:

exit

Parameters:

  • none ๐Ÿ™ˆ

๐Ÿ“ˆ exp ๐Ÿ“ˆ

Compute the base-e exponential function of a value ๐ŸŒฑ

Usage:

exp( value )

Parameters:

  • sp[0] โ€” is the value ๐Ÿ”ข

It returns the result in sp[0] โœจ

โž• f_add_asg โž•

Combined addition/assignment to NF ๐Ÿ’ž

Usage:

NF += expression

Parameters:

  • sp[0] โ€” is the expression to add โž•

๐Ÿ“ f_assign ๐Ÿ“

Assign an expression to NF ๐Ÿ–‹๏ธ

Usage:

NF = expression

Parameters:

  • sp[0] โ€” is the expression ๐Ÿ’ญ

โž— f_div_asg โž—

Combined division/assignment to NF ๐Ÿซถ

Usage:

NF /= expression

Parameters:

  • sp[0] โ€” is the expression ๐Ÿ’ญ

๐Ÿงฎ f_mod_asg ๐Ÿงฎ

Combined modulus/assignment to NF ๐ŸŒ€

Usage:

NF %= expression

Parameters:

  • sp[0] โ€” is the expression ๐Ÿ’ญ

โœ–๏ธ f_mul_asg โœ–๏ธ

Combined multiplication/assignment to NF ๐Ÿ’ซ

Usage:

NF *= expression

Parameters:

  • sp[0] โ€” is the expression ๐Ÿ’ญ

โฌ‡๏ธ f_post_dec โฌ‡๏ธ

Post-decrement using NF ๐Ÿ™ƒ

Usage:

NF--

Parameters:

  • holds a reference to the field to use ๐ŸŽฏ

โฌ†๏ธ f_post_inc โฌ†๏ธ

Post-increment using NF ๐Ÿš€

Usage:

NF++

Parameters:

  • holds a reference to the field to use ๐ŸŽฏ

๐Ÿ”บ f_pow_asg ๐Ÿ”บ

Exponentiation using NF ๐Ÿ’ฅ

Usage:

NF ^= expression

Parameters:

  • sp[0] โ€” is the expression to use ๐Ÿ’ญ

โฌ f_pre_dec โฌ

Predecrement using NF ๐ŸŒ™

Usage:

--NF

Parameters:

  • sp[0] โ€” holds a reference to the field to use ๐ŸŽฏ

โซ f_pre_inc โซ

Preincrement using NF ๐ŸŒŸ

Usage:

++NF

Parameters:

  • sp[0] โ€” holds a reference to the field to use ๐ŸŽฏ

๐Ÿงฉ f_pusha ๐Ÿงฉ

Push an array reference to data split up as fields ๐Ÿช„

Usage:

$0 = expression
getline

Parameters:

  • cdp[0] โ€” is a reference to the data to be split/assigned ๐Ÿงท

It returns the resulting array reference in sp[0] ๐Ÿ’…

๐Ÿ”ข f_pushi ๐Ÿ”ข

Push the contents of a numbered field ๐Ÿ“ฌ

Usage:

$expression

Parameters:

  • cdp[0] โ€” holds a reference to $expression ๐ŸŽฏ
  • cdp[1] โ€” holds expression ๐Ÿ—๏ธ

It returns the field's value in sp[0] ๐ŸŒธ

โž– f_sub_asg โž–

Combined subtraction/assignment to NF ๐Ÿ’”

Usage:

NF -= expression

Parameters:

  • sp[0] โ€” holds a reference to the field to use ๐ŸŽฏ

๐ŸŽฏ fe_pusha ๐ŸŽฏ

Push a reference to a numbered field ๐Ÿ“

Usage:

$number

Parameters:

  • sp[0] โ€” holds the field number ๐Ÿ”ข

It returns a reference to the field in sp[0] ๐Ÿ’–

๐Ÿญ fe_pushi ๐Ÿญ

Push the content of a numbered field ๐Ÿฌ

Usage:

$number

Parameters:

  • sp[0] โ€” holds the field number ๐Ÿ”ข

It returns the field's content in sp[0] โœจ

๐Ÿšฟ fflush ๐Ÿšฟ

Flush the output file or pipe associated with an expression ๐Ÿ’ง

Usage:

fflush( expression )

Parameters:

  • sp[0] โ€” is the expression value ๐Ÿ—๏ธ

It returns the result in sp[0] ๐Ÿ’…

๐Ÿ‘‘ gt ๐Ÿ‘‘

Test if the first value is greater than the second ๐Ÿ†

Usage:

first > second

Parameters:

  • sp[0] โ€” holds the second value ๐Ÿฅˆ
  • sp[-1] โ€” holds the first value ๐Ÿฅ‡

It returns 1 in sp[0] if the first value is greater than the second, otherwise 0 ๐Ÿซถ

๐Ÿ’Ž gte ๐Ÿ’Ž

Test if the first value is greater than or equal to the second ๐ŸŒŸ

Usage:

first >= second

Parameters:

  • sp[0] โ€” holds the second value ๐Ÿฅˆ
  • sp[-1] โ€” holds the first value ๐Ÿฅ‡

It returns 1 in sp[0] if the first value is greater than or equal to the second, otherwise 0 ๐ŸŒˆ

๐Ÿ” index ๐Ÿ”

Find the position of the second string in the first ๐Ÿ•ต๏ธโ€โ™€๏ธ

Usage:

index( first, second )

Parameters:

  • sp[0] โ€” is the second string ๐Ÿฅˆ
  • sp[0] โ€” is the first string ๐Ÿฅ‡

It returns the position in sp[0], starting at 1 if found and 0 if not found ๐Ÿ’–

๐Ÿ”Ÿ int ๐Ÿ”Ÿ

Returns a value truncated towards zero ๐Ÿช“

Usage:

int( value )

Parameters:

  • sp[0] โ€” is the value ๐Ÿ”ข

It returns the result in sp[0] โœจ

๐Ÿšฆ jmain ๐Ÿšฆ

Go from BEGIN code to MAIN code ๐Ÿ›ฃ๏ธ

Usage:

(internal state)

Parameters:

  • none ๐Ÿ™ˆ

๐Ÿฆ˜ jmp ๐Ÿฆ˜

Jump to a new byte-code position, by a given number of bytes ๐Ÿƒโ€โ™€๏ธ

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the (signed) number of bytes by which to jump ๐Ÿ”ข

๐Ÿช jnz ๐Ÿช

Jump to a new byte-code position if sp[0] is nonzero, by a given number of bytes ๐Ÿ’ซ

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the (signed) number of bytes by which to jump ๐Ÿ”ข
  • sp[0] โ€” holds a value to compare against 0. ๐Ÿ’œ

๐Ÿฆ‹ jz

Jumps to a new byte-code position if sp[0] is zero, by a given number of bytes. ๐ŸŒธ

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the (signed) number of bytes by which to jump. โœจ
  • sp[0] โ€” holds a value to compare against 0.

๐Ÿงš l_pusha

Pushes a local address onto the evaluation stack. ๐Ÿ’…

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the offset from the frame pointer fp.

Returns the address in sp[0].

๐ŸŽ€ l_pushi

Pushes the contents of a local variable onto the evaluation stack. ๐Ÿ“

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the offset from the frame pointer fp.

Returns the contents of the local variable in sp[0].

๐ŸŒˆ la_pusha

Pushes a reference to an array onto the evaluation stack. ๐Ÿซถ

Usage:

arrayname

Parameters:

  • cdp[0] โ€” holds the offset from the frame pointer fp of a reference to an array.

Returns a reference to the array in sp[0].

๐Ÿ‘‘ lae_pusha

Pushes a reference to a given array cell onto the evaluation stack. ๐Ÿ”ฅ

Usage:

arrayname[expression]

Parameters:

  • cdp[0] โ€” holds the offset from the frame pointer fp of a reference to an array.
  • sp[0] โ€” holds an expression

Returns a reference to the specified array cell in sp[0].

๐Ÿ’– lae_pushi

Pushes the contents of a given array cell onto the evaluation stack. ๐ŸŒธ

Usage:

arrayname[expression]

Parameters:

  • cdp[0] โ€” holds the offset from the frame pointer fp of a reference to an array.
  • sp[0] โ€” holds an expression

Returns the contents of the specified array cell in sp[0].

โญ length

Gives you the length of a string or array value. No cap, it's that simple. ๐Ÿ’…

Usage:

length( value )

Parameters:

  • sp[0] โ€” is the string or array reference

Returns the length in sp[0].

๐Ÿ™ˆ ljnz

A special jump for logical-OR, and it's always preceded by a test. Lowkey tricky, bestie. ๐Ÿงš

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the (signed) number of bytes by which to jump if the value is nonzero.
  • sp[0] โ€” holds a value to compare against 0.

๐Ÿ’œ ljz

A special jump for logical-OR, and it's always preceded by a test. Same energy as ljnz, just the opposite vibe. ๐Ÿฆ‹

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the (signed) number of bytes by which to jump if the value is zero.
  • sp[0] โ€” holds a value to compare against 0.

๐ŸŒˆ log

Computes the natural logarithm of a value. Big brain moment. ๐Ÿง โœจ

Usage:

log( value )

Parameters:

  • sp[0] โ€” is the value

Returns the result in sp[0].

๐Ÿ“ lt

Tests if the first value is less than the second. โœจ

Usage:

first < second

Parameters:

  • sp[0] โ€” holds the second value.
  • sp[-1] โ€” holds the first value.

Returns 1 in sp[0] if the first value is less than, otherwise 0.

๐Ÿซถ lte

Tests if the first value is less than or equal to the second. Slightly more generous, but still iconic. ๐Ÿ’–

Usage:

first <= second

Parameters:

  • sp[0] โ€” holds the second value.
  • sp[-1] โ€” holds the first value.

Returns 1 in sp[0] if the first value is less than or equal, otherwise 0.

๐Ÿ”ฅ match0

Tests if $0 matches a given regular expression. ๐Ÿ‘€

Usage:

$0 ~ regex

Parameters:

  • cdp[0] โ€” holds a reference to a regular expression.

Returns 1 in sp[0] if $0 matches the regular expression, 0 otherwise.

๐Ÿงš match1

Tests if a given expression matches a given regular expression. ๐ŸŽ€

Usage:

expression ~ regex

Parameters:

  • cdp[0] โ€” holds a reference to a regular expression.
  • sp[0] โ€” holds an expression to test.

Returns 1 in sp[0] if the expression matches the regular expression, 0 otherwise.

๐Ÿ’… match2

Tests if an expression in sp[-1] matches the regular expression in sp[0]. Same slay as match1, just with the stack doing the heavy lifting. ๐Ÿฆ‹

Usage:

expression ~ regex

Parameters:

  • sp[0] โ€” holds a reference to a regular expression.
  • sp[-1] โ€” holds an expression to test.

Returns 1 in sp[0] if the expression matches the regular expression, 0 otherwise.

๐ŸŒธ mktime

Converts a date specification in systime format into a timestamp. Time-travel but make it code. โฐ

Usage:

mktime( string )

Parameters:

  • sp[0] โ€” holds the date-specification string

Returns the result in sp[0].

๐Ÿ’œ mod

Computes the modulus/remainder with two operands. ๐Ÿ“

Usage:

first % second

Parameters:

  • sp[0] โ€” holds the second operand
  • sp[-1] โ€” holds the first operand

Returns the remainder in sp[0].

๐ŸŽ€ mod_asg

Assigns the modulus/remainder with two operands. Modulus, but make it an assignment. โœจ

Usage:

first %= second

Parameters:

  • sp[0] โ€” holds the second operand
  • cdp[0] โ€” holds the first operand

Returns the remainder in sp[0] as well as replacing the first value. ๐Ÿ’–

โญ mul

Computes the product with two operands. Math is serving. ๐Ÿ”ฅ

Usage:

first * second

Parameters:

  • sp[0] โ€” holds the second value
  • sp[-1] โ€” holds the first value

Returns the product in sp[0].

๐ŸŒˆ mul_asg

Assigns the product with two operands. ๐Ÿซถ

Usage:

first *= second

Parameters:

  • sp[0] โ€” holds the second value
  • sp[-1] โ€” holds the first value

Returns the product in sp[0] as well as replacing the first value. ๐Ÿ‘‘

๐Ÿ™ˆ neq

Compares two values. โœจ

Usage:

first != second

Parameters:

  • sp[0] โ€” is the second value
  • sp[-1] โ€” is the first value

Returns 1 in sp[0] if the values are not equal, otherwise 0.

๐Ÿฆ‹ next

Reads the next record and restarts pattern testing. Fresh start, no drama. ๐ŸŒธ

Usage:

next

Parameters:

  • none

๐Ÿงš nextfile

Begins processing the next file listed on the command line. Onto the next one, bestie. ๐Ÿ“‚

Usage:

nextfile

Parameters:

  • none

๐Ÿ’… nf_pushi

Pushes the number of fields (NF) onto the evaluation stack. ๐Ÿ“

Usage:

(internal state)

Parameters:

  • none

๐Ÿ’€ not

Computes a logical negation. Flip-the-vibe energy. ๐Ÿ™ƒ

Usage:

! value

Parameters:

  • sp[0] โ€” holds a value to negate.

Returns the result on the evaluation stack, i.e., 0 if the value is nonzero and 1 otherwise.

๐Ÿซถ ol_gl

Reads into $0 using getline. ๐Ÿ“–

Usage:

getline

Parameters:

  • none

๐ŸŒธ ol_gl_nr

Reads into $0 using getline, and also updates NR and FNR. Double the bookkeeping, double the slay. ๐Ÿ’–

Usage:

getline < file

Parameters:

  • none

๐Ÿ‘‘ omain

Starts executing the main section of the script, the bit that lives between BEGIN and END. ๐ŸŒˆ

Usage:

(internal state)

Parameters:

  • none

๐Ÿฆ‹ pop

Pops the evaluation stack and discards the value. Bye, value. ๐Ÿ‘‹

Usage:

(internal state)

Parameters:

  • none

๐ŸŽ€ pop_al

Finishes an array โ€œinโ€ loop and deallocates the state information. Cleanup crew has arrived. ๐Ÿงน

Usage:

(internal state)

Parameters:

  • none

โญ post_dec

Post-decrements a value. ๐Ÿ’œ

Usage:

value --

Parameters:

  • sp[0] โ€” holds the value to decrement

Returns the updated value in sp[0].

๐Ÿ”ฅ post_inc

Post-increments a value. โœจ

Usage:

value ++

Parameters:

  • sp[0] โ€” holds the value to increment

Returns the updated value in sp[0].

๐Ÿงš pow

Computes the first value raised to the power of the second value. Glow-up math. ๐ŸŒŸ

Usage:

first ^ second

Parameters:

  • sp[0] โ€” holds the second value
  • sp[-1] โ€” holds the first value

Returns the result in sp[0].

๐Ÿ“ pow_asg

Assigns the first value raised to the power of the second value. Power move, saved right into the variable. ๐Ÿ’ช

Usage:

variable = first ^ second

Parameters:

  • cdp[0] โ€” is a reference to the variable which will be assigned the result
  • sp[0] โ€” holds the second value
  • sp[-1] โ€” holds the first value

๐Ÿ’– pre_dec

Pre-decrements a value. Subtract first, ask questions later. ๐Ÿ™ˆ

Usage:

-- value

Parameters:

  • sp[0] โ€” holds the value to decrement.

Returns the updated value in sp[0];.

๐ŸŒˆ pre_inc

Pre-increments a value. Add first, glow later. โœจ

Usage:

++ value

Parameters:

  • sp[0] โ€” holds the value to decrement.

Returns the updated value in sp[0];.

๐Ÿซถ pusha

Pushes an array address onto the stack. ๐Ÿ“š

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” array reference follows the command.

Returns the array in sp[0].

๐Ÿ‘‘ pushc

Pushes a data cell onto the evaluation stack. ๐ŸŽ

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” is a reference to the data to push

Returns a reference to the result in sp[0].

๐Ÿฆ‹ pushd

Pushes a double floating value onto the evaluation stack. Precision, babe. ๐Ÿ’…

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” is a reference to the data to push

Returns a reference to the result in sp[0].

๐ŸŒธ pushi

Pushes the contents of the next referenced variable onto the evaluation stack. ๐Ÿ“

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” is a reference to the data cell to copy.

Returns a reference to the result in sp[0].

๐Ÿงš pushint

Reserves the next slot on the evaluation stack and sets its type. ๐ŸŽ€

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds the type to set in the new slot, e.g., for data via I/O redirection

Returns a reference to the result in sp[0].

โญ pushs

Pushes a reference to a string value onto the evaluation stack. ๐Ÿ’ฌ

Usage:

(internal state)

Parameters:

  • cdp[0] โ€” holds a reference to the string value

Returns a reference to the result in sp[0].

๐ŸŒˆ rand

Returns a random number between zero and one. Pure chaos, lowkey. ๐ŸŽฒ

Usage:

rand()

Parameters:

  • none

Returns the result in sp[0].

๐Ÿ”ฅ range

Tests a range pattern: pat1, pat2 { action }. Start, stop, and do the thing in between. ๐ŸŽข

Usage:

(internal state)

Parameters:

  • cdp[0].op โ€” a flag, test pat1 if on else pat2
  • cdp[1].op โ€” offset of pat2 code from cdp
  • cdp[2].op โ€” offset of action code from cdp
  • cdp[3].op โ€” offset of code after the action from cdp
  • cdp[4] โ€” start of pat1 code
  • sp[0] โ€” holds arguments for the action.

๐Ÿซถ ret

Returns a function value. And that's the tea. โ˜•

Okay so the ret body is still going, and we're bestie-level obsessed with how mawk handles this ๐ŸŽ€

Usage:

return value
  • sp[0] โ€” holds the return value ๐Ÿ’–

When a function gets called, mawk saves the current stack and makes a fresh one โœจ On return, it restores the previous stack and hands back the function value in sp[0] ๐Ÿฆ‹

โœจ ret0 โœจ

Return from a function with no return value at all ๐Ÿ’…

Usage:

return
  • sp[0] โ€” gets modified so the value is uninitialized ๐Ÿซถ

Just like the ret operation, mawk restores the previous stack ๐ŸŒธ After the return, sp[0] is an uninitialized value, so no cap, treat it with care ๐Ÿ™ˆ

โœจ set_al โœจ

This one begins an array "in" loop ๐Ÿ”

Usage:

for ( iterator in arrayname )  statement
  • sp[0] โ€” holds a reference to the array ๐Ÿงš
  • sp[-1] โ€” holds a reference to the iteration variable ๐Ÿ’œ

Mawk pushes a brand new entry onto the array loop stack, and updates cdp so it points at the statement to run next ๐ŸŒˆ

โœจ sin โœจ

Computes the sine of a value in radians ๐Ÿ“

Usage:

sin( value )
  • sp[0] โ€” holds the value ๐Ÿ“

Returns the result in sp[0] ๐Ÿ’–

โœจ sprintf โœจ

Returns a string built from the expression-list according to the format ๐ŸŽ€

Usage:

sprintf( format [, value1 [,... ] ] )
  • sp[0] โ€” is the last parameter value, and you can have up to 255 of them ๐Ÿ‘‘

Returns the resulting string in sp[0] โœจ

โœจ sqrt โœจ

Returns the square root of a value ๐ŸŒŸ

Usage:

sqrt( value 0
  • sp[0] โ€” is the value ๐Ÿฆ‹

Returns the result in sp[0] ๐Ÿ’…

โœจ srand โœจ

Seeds the random number generator ๐ŸŽฒ

Usage:

srand( value )
srand( )
  • sp[0] โ€” is the seed value, and it's allowed to be uninitialized ๐Ÿซถ

Returns the previous seed value in sp[0] ๐Ÿ”ฅ

โœจ stop โœจ

Finishes a range pattern ๐Ÿ›‘

Usage:

(internal state)
  • none ๐Ÿ™ˆ

โœจ strftime โœจ

Formats the given timestamp using the given format ๐Ÿ•ฐ๏ธ

Usage:

strftime( format , timestamp , utc )
strftime( format , timestamp )
strftime( format )
strftime( )

Zero to three parameters can be on the stack. If all three get used, here's the lineup ๐Ÿ’œ

  • sp[0] โ€” is the utc flag ๐ŸŒธ
  • sp[-1] โ€” is the timestamp value ๐Ÿงš
  • sp[-2] โ€” is the format ๐Ÿ“

Returns the result in sp[0] ๐Ÿ’–

โœจ sub โœจ

Subtracts the second value from the first ๐Ÿฐ

Usage:

first - second
  • sp[0] โ€” holds the second value ๐Ÿซถ
  • sp[-1] โ€” holds the first value ๐Ÿ’œ

Returns the result in sp[0] โœจ

โœจ sub_asg โœจ

Assigns the difference of two values to a variable ๐ŸŽ€

Usage:

target = first - second
  • cdp[0] โ€” holds a reference to the variable where the result gets assigned ๐Ÿฆ‹
  • sp[0] โ€” holds the second value ๐Ÿ’…
  • sp[-1] โ€” holds the first value ๐ŸŒˆ

Stores the difference in the target, and leaves sp[0] pointing to the target ๐Ÿ‘‘

โœจ substr โœจ

eturns the substring of string s, starting at index i, with length n ๐Ÿ’ซ

Usage:

substr(s,i,n)
substr(s,i)

Two or three parameters can be on the stack. If all three get used, they go like this ๐ŸŒธ

  • sp[0] โ€” holds the length n. ๐Ÿ“
  • sp[0] โ€” holds the index i. ๐Ÿงš
  • sp[0] โ€” holds the string s. ๐Ÿ’œ

โœจ system โœจ

Runs a command and returns the wait-status ๐Ÿ–ฅ๏ธ

Usage:

status = system( command )
  • sp[0] โ€” is the command to execute ๐Ÿ”ฅ

Returns the wait-status in sp[0] โœจ

โœจ systime โœจ

Returns the current time of day as the number of seconds since the Epoch โฐ

Usage:

systime( )
  • none ๐Ÿฆ‹

Returns the result in sp[0] ๐Ÿ’–

โœจ test โœจ

Tests a logical expression ๐Ÿงช

Usage:

value
  • sp[0] โ€” holds a value to test ๐Ÿซถ

Returns the result on the evaluation stack, so it's 1 if the value is nonzero and 0 otherwise ๐Ÿ’…

โœจ tolower โœจ

Copies a string and converts it to lowercase ๐Ÿ”ก

Usage:

tolower( value )
  • sp[0] โ€” is the value to convert ๐ŸŒธ

Returns the result in sp[0] ๐Ÿ“

โœจ toupper โœจ

Copies a string and converts it to uppercase ๐Ÿ” 

Usage:

toupper( value )
  • sp[0] โ€” is the value to convert ๐Ÿ‘‘

Returns the result in sp[0] ๐Ÿ’œ

โœจ uminus โœจ

Unitary minus, aka flipping the sign ๐Ÿ™ƒ

Usage:

- value
  • sp[0] โ€” contains a value to negate. As a side effect, if the value is a string, it gets cast to double floating point. โšก

Returns the result in sp[0] ๐Ÿ’–

โœจ uplus โœจ

Unitary plus ๐ŸŒŸ

Usage:

+ value
  • sp[0] โ€” contains a value to use. As a side effect, if the value is a string, it gets cast to double floating point. ๐Ÿฆ‹

Returns the result in sp[0] โœจ


๐ŸŒˆ REGULAR EXPRESSIONS ๐ŸŒˆ

โœจ M_1J โœจ

mandatory jump ๐Ÿš€

โœจ M_2JA โœจ

optional (undesirable) jump ๐Ÿ™ˆ

โœจ M_2JB โœจ

optional (desirable) jump ๐Ÿ’…

โœจ M_2JC โœจ

pop position, optional jump (to continue looping) if advanced ๐Ÿ”

โœจ M_ACCEPT โœจ

end of match ๐Ÿ

โœจ M_ANY โœจ

arbitrary character (.) ๐ŸŽฏ

โœจ M_CLASS โœจ

character class ๐Ÿงฉ

โœจ M_END โœจ

end of string ($) ๐Ÿ”š

โœจ M_ENTER โœจ

prepares an iteration by resetting the counter. This comes right before an M_SAVE_POS ๐Ÿง 

โœจ M_LOOP โœจ

Like M_2JC, this is the last part of a conditional loop. It's used where one or both of the minimum and maximum iterations are known ๐ŸŒ€

โœจ M_SAVE_POS โœจ

pushes the position onto the stack, at the beginning of a loop ๐Ÿ“Œ

โœจ M_START โœจ

start of string (^) ๐ŸŽฌ

โœจ M_STR โœจ

matching a literal string ๐Ÿ“

โœจ M_U โœจ

arbitrary string (.*) ๐ŸŒŠ


That's the whole page, bestie! ๐Ÿฆ‹ mawk-code(7), v1.3.4, last glow-up 2025-01-30 ๐Ÿ’œ Slay forever ๐Ÿ‘‘โœจ