The awk file, for example example.awk, should have a header #!/bin/bashor #!/bin/awk -f?
The reason for my question is that if I try this command in the console, I get the correct .txt file with a "line of text":
awk 'BEGIN {print "line of text"}' >> file.txt
but if I try to execute the following file with. /example.awk:
awk 'BEGIN {print "line of text"}' >> file.txt
it returns an error:
$ ./awk-usage.awk
awk: ./awk-usage.awk:3: awk 'BEGIN {print "line of text"}' >> file.txt
awk: ./awk-usage.awk:3: ^ invalid char ''' in expression
If I change the title to #!/bin/bashor #!/bin/sh, it works.
What is my mistake? What is the reason for this?
source
share