I'm just trying to get started writing an awk script to test for inclusion in an array, however I seem to have a basic syntax error someplace.
#!/bin/bash
awk \
BEGIN {'myarray["foo"] = "bar" '} \
{' \
print "$1" \
'} $1
If I take out the BEGIN line, then indeed the rest of the script works.
I have also tried it like this:
#!/bin/bash
awk \
{' \
myarray["foo"] = "bar" \
print "$1" \
'} $1
Here's the error I'm getting.
awk: syntax error at source line 1
context is
>>> <<<
awk: bailing out at source line 1
{'myarray....'}. Normally you should just surround the whole awk script with one set of single quotes likeawk 'BEGIN{ ...} { ..... } END {...}file > outFile`. You can get fancy with dbl-quotes to all allow shell vars to be visible, but @FredrikPihl 's advice is good. Good luck.