0

Running GNU Awk 3.1.1 on an openvms system. Anyone know how I can output a double quote character. Tried various ways with no luck e.g

$ gawk "BEGIN {print "Hello, World"}" NL:
/chas$dka0/psx$root/bin/gawk: cmd. line:2: (END OF FILE)
/chas$dka0/psx$root/bin/gawk: cmd. line:2: parse error

$ gawk "BEGIN {print "\"Hello, World\""}" NL:
/chas$dka0/psx$root/bin/gawk: cmd. line:1: BEGIN {print \Hello, World\"}
/chas$dka0/psx$root/bin/gawk: cmd. line:1:              ^ backslash not last character on line

Closest I get is

$ gawk "BEGIN {print ""Hello, World""}" NL:
Hello, World

But no leading or trailing " appears

user2699504
  • 195
  • 1
  • 4
  • 18

2 Answers2

0

Got it!

$ gawk -v qte="""" "BEGIN {print qte""hello world""qte}" NL:
"hello world"
user2699504
  • 195
  • 1
  • 4
  • 18
0

Or you can use

$ gawk "BEGIN {print ""\""Hello, World\""""}" nl:

As you probably know, for DCL to have a quote character in a string, you have to double it. For DCL the gawk program text is a quoted string. In the program text you need another string, a gawk quoted string. So DCL replaces all doubled quote characters by a single one. In other words, DCL passes

BEGIN {print "\"Hello, World\""}

as the program text to gawk. This can be verified with a simple

$ write sys$output "BEGIN {print ""\""Hello, World\""""}"

Within a gawk string you have to escape the gawk quote character with '\'.

In your solution DCL passes

BEGIN {print qte"hello world"qte}

as program text to gawk, which prints the contents of qte, the string `hello world' and again the contents of qte.

user2116290
  • 1,062
  • 5
  • 6