The print statement
So far, we have been using print
statements mainly to produce simple yet standardized output.With a print
statement, we specify theexpressionsto print as a list separated by commas. The output is separated by single spaces, followed by a newline. The print
statement has two forms:
print expr1, expr2, ……, exprn print (expr1, expr2, ………, exprn)
Both print the string value of each expression separated by the Output Field Separator (OFS); the default is a single space followed by the Output Record Separator (ORS); the default is newline. Using parentheses is necessary if an expression uses the >
relational operator to mark its differentiation from redirection operator. Here expression could be any AWK expression or any constant string, or number, or field of current input record (like $1
, $2
, ... and so on). Numeric values are automatically converted to string, and then printed. For example, if we want to print the first two fields from the car
database using a simple print...