Go forward to Print Examples.
Go backward to Printing.
Go up to Printing.
The `print' Statement
=====================
The `print' statement does output with simple, standardized
formatting. You specify only the strings or numbers to be printed, in a
list separated by commas. They are output, separated by single spaces,
followed by a newline. The statement looks like this:
print ITEM1, ITEM2, ...
The entire list of items may optionally be enclosed in parentheses. The
parentheses are necessary if any of the item expressions uses a
relational operator; otherwise it could be confused with a redirection
(see Redirecting Output of `print' and `printf': Redirection.). The
relational operators are `==', `!=', `<', `>', `>=', `<=', `~' and `!~'
(see Comparison Expressions: Comparison Ops.).
The items printed can be constant strings or numbers, fields of the
current record (such as `$1'), variables, or any `awk' expressions.
The `print' statement is completely general for computing *what* values
to print. With two exceptions, you cannot specify *how* to print
them--how many columns, whether to use exponential notation or not, and
so on. (See Output Separators, and *Note Controlling Numeric
Output with `print': OFMT.) For that, you need the `printf' statement
(see Using `printf' Statements for Fancier Printing: Printf.).
The simple statement `print' with no items is equivalent to `print
$0': it prints the entire current record. To print a blank line, use
`print ""', where `""' is the null, or empty, string.
To print a fixed piece of text, use a string constant such as
`"Hello there"' as one item. If you forget to use the double-quote
characters, your text will be taken as an `awk' expression, and you
will probably get an error. Keep in mind that a space is printed
between any two items.
Most often, each `print' statement makes one line of output. But it
isn't limited to one line. If an item value is a string that contains a
newline, the newline is output along with the rest of the string. A
single `print' can make any number of lines this way.