# awk

In multiline `awk` programs/scripts, actions preceded by `BEGIN`, a predicate (test-action), or `END` should insert a space before the opening curly brace (`{`). Single-line actions should insert a space after the opening curly and before the ending curly. Functions should insert a newline before/after the opening/closing curly brace. If the function can be written on a single-line in less than 80 characters, space can be used instead of newline.

```
function abc() { ... }
function def()
{
    ...
}
BEGIN { ... }
BEGIN {
    ...
}
{ ... }
{
    ...
}
test { ... }
test {
    ...
}
start, stop { ... }
start, stop {
    ...
}
END { ... }
END {
    ...
}
```

Localized function variables declared in the argument scope should be preceded by eight (8) spaces to separate them from the intended function arguments. If the arguments and locals together would exceed 79 characters, separate arguments and locals with a newline.

```
function abc(arg1, arg2,        local1, local2)
{
    ...
}
function def(arg1, arg2,
    local1, local2, local3, local4, local5, local6, local7, local8, local9,
    local10, local11)
{
    ...
}
function ghi(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
    arg11, arg12,
    local1, local2, local3)
{
    ...
}
```

Precede functions with intended syntax and description.

```
# add(arg1, arg2)
#
# Show addition. Returns sum of arg1 and arg2.
#
function add(arg1, arg2,        sum)
{
    sum = arg1 + arg2
    printf "%u + %u = %u\n", arg1, arg2, sum
    return int(sum)
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://freebsdfrau.gitbook.io/serious-shell-programming/style/awk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
