awk - I can't print to file

0

I don't know ,why I can't print from to file. My command:

awk 'BEGIN{print "af">file}'

Error:

fatal: expression for `>>' redirection has null string value

diego9403

Posted 2015-09-01T17:44:31.790

Reputation: 807

Answers

2

file needs to be in quotes else awk will attempt to parse file as a variable rather than a string:

 awk 'BEGIN{print "af">"file"}'

suspectus

Posted 2015-09-01T17:44:31.790

Reputation: 3 957

... or else file has to be assigned a value: awk 'BEGIN {file="mytest"; print "af">file}'. – Scott – 2015-09-02T05:16:30.177