The print
statement in awk
takes one of three forms:
print > expression
print >> expression
print | expression
... where the >
, >>
, and |
bit, and the expression
that follows, are optional.
The print > expression
command will cause the output to go to a file named by whatever string that expression
evaluates to. If the file exists, it will be truncated (emptied). This is similar to how output redirection in the shell works, but the file will not be truncated by executing the same print
statement a second time, unless close(expression)
is used to close the file related to expression
first.
The >>
and |
forms of the print
command are also inspired by how the shell handles these tokens but see an awk
manual for further information about these forms.
In your code, you have
print 3 > 5 ? "Hello" : "World"
This matches the print > expression
syntax and would therefore output the string 3
to a file called 5
. The rest of that line continues with a question mark, which your awk
can't make much sense out of, so it complains about it. Some awk
implementations would use the 5 ? "Hello" : "World"
bit as the expression
and would therefore write 3
to a file called Hello
(since 5
is a true value when used as a boolean).
What you most likely wanted to do is
print ( 3 > 5 ? "Hello" : "World" )
or
print ( 3 > 5 ) ? "Hello" : "World"
This ensures that the print > expression
syntax isn't triggered.