literal characters

Special characters cannot be directly included in a literal string

Special characters, such as [[control_character?]]s or [[metacharacter?]]s cannot be included directly in a string value. This is because these [[character?]]s have a special meaning to the awk interpreter, and may cause [[misbehaviour?]] of the [[script?]]. These [[character?]]s can be inserted as literal characters by using literal character notation.

Literal Character Notation

Literal character notation enables [[special_character?]]s to represented in a string by using a [[representation_code?]] that begins with a backslash symbol:

Literal Character Representation Digraphs

The following table shows literal characters that can be represented using the backslash, together with the digraphical representation codes:

Digraph Literal character
\a ring the terminal bell
\b backspace
\c suppress subsequent output
\e ascii escape
\f form feed
\n newline
\r carriage return
\t tab
\v vertical tab

backslash

Numerical Literal Character Representation

Literal ascii character codes can also be output using a numeric representation code:

Representation Literal character
\0dd dd is the octal character code of the represented ascii character

Using a backslash to insert literal characters into a string

The following example shows how a backslash symbol is used to insert literal characters into a string. Note that the \n digraph is used to represent a newline character:

{{{

print "first line\nsecond line" # The \n represents a newline character in a string

}}}

The above literal string contains an embedded newline character and should print as follows:

 first line
 second line