An awk assignment is also an expression with the return value of what was assigned. If you write
if (myVar = "optA")
you actually check the return value of the assignment, optA, which awlays evaluates to "true". You want
if (myVar == "optA")
for comparison instead of assignment.
Also, you can't have "naked" statements like this. Your if/else clause either has to be part of the BEGIN block:
BEGIN {
printf "TITLE:\nDocuments \n", myVar, FS=" "
if (myVar=="optA")
printf myVar
else
printf "OptB"
}
to execute once, or in a separate block if it should be executed for every single line (less likely, though):
BEGIN { printf "TITLE:\nDocuments \n", myVar, FS=" " }
{
if (myVar=="optA")
printf myVar
else
printf "OptB"
}
As an aside, the way you use printf doesn't make much sense: you could either do
print "TITLE:\nDocuments\n" myVar
or
printf "TITLE:\nDocuments\n%s\n", myVar
And for printf myVar or printf "OptB", unless you explicitly don't want that newline, you can as well use print myVar and print "OptB".
And finally, that FS= assignment looks a bit out of place and is probably not needed as " " is the default value of FS.
FS=" ". Also, you probably don't even need thatFSassignment at all, because the default input field separator is white space.