Go forward to OFMT.
Go backward to Print Examples.
Go up to Printing.
Output Separators
=================
As mentioned previously, a `print' statement contains a list of
items, separated by commas. In the output, the items are normally
separated by single spaces. But they do not have to be spaces; a
single space is only the default. You can specify any string of
characters to use as the "output field separator" by setting the
built-in variable `OFS'. The initial value of this variable is the
string `" "', that is, just a single space.
The output from an entire `print' statement is called an "output
record". Each `print' statement outputs one output record and then
outputs a string called the "output record separator". The built-in
variable `ORS' specifies this string. The initial value of the
variable is the string `"\n"' containing a newline character; thus,
normally each `print' statement makes a separate line.
You can change how output fields and records are separated by
assigning new values to the variables `OFS' and/or `ORS'. The usual
place to do this is in the `BEGIN' rule (*note `BEGIN' and `END'
Special Patterns: BEGIN/END.), so that it happens before any input is
processed. You may also do this with assignments on the command line,
before the names of your input files.
The following example prints the first and second fields of each
input record separated by a semicolon, with a blank line added after
each line:
awk 'BEGIN { OFS = ";"; ORS = "\n\n" }
{ print $1, $2 }' BBS-list
If the value of `ORS' does not contain a newline, all your output
will be run together on a single line, unless you output newlines some
other way.