AWK - AWK Commands - The print Command

The print Command

The print command is used to output text. The output text is always terminated with a predefined string called the output record separator (ORS) whose default value is a newline. The simplest form of this command is:

print
This displays the contents of the current record. In AWK, records are broken down into fields, and these can be displayed separately:
print $1
Displays the first field of the current record
print $1, $3
Displays the first and third fields of the current record, separated by a predefined string called the output field separator (OFS) whose default value is a single space character

Although these fields ($X) may bear resemblance to variables (the $ symbol indicates variables in Perl), they actually refer to the fields of the current record. A special case, $0, refers to the entire record. In fact, the commands "print" and "print $0" are identical in functionality.

The print command can also display the results of calculations and/or function calls:

print 3+2 print foobar(3) print foobar(variable) print sin(3-2)

Output may be sent to a file:

print "expression" > "file name"

or through a pipe:

print "expression" | "command"

Read more about this topic:  AWK, AWK Commands

Famous quotes containing the word command:

    Under bare Ben Bulben’s head
    In Drumcliff churchyard Yeats is laid.
    An ancestor was rector there
    Long years ago, a church stands near,
    By the road an ancient cross.
    No marble, no conventional phrase;
    On limestone quarried near the spot
    By his command these words are cut:
    Cast a cold eye
    On life, on death.
    Horseman pass by!
    William Butler Yeats (1865–1939)