It isn't clear exactly what more needs to be escaped in the following macro to allow it to be used with awk or sed on FreeBSD.

define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl

Here is an awk command that attempts to insert the above line at line 90 below the SMART_HOST configuration.

awk 'NR==90 { print "define(\`RELAY_MAILER_ARGS\', \`TCP $h 2525\')dnl"}1' example.com.mc

The command results in the following error:

Unmatched '"'.

Note to future editors: the backtick/single quote is not a typo. This is an ancient quirk of the m4 language that is used to write the macros for Sendmail configuration: "m4 uses single quotes (opening "`" and closing "'") to quote arguments"

Additional Note: Octal escapes don't seem to work when using sed on FreeBSD. In that situation, use the xNN escaped hexadecimal characters in that situation.

1 Answer 1


You cannot escape single quotes as the command itself is surrounded by single quotes, but you could use an octal escape code \047 to represent ' in POSIX awk. Additionally, you could use a hexadecimal escape code \x27 in GNU awk (gawk).

From The GNU Awk User’s Guide, 3.2 Escape Sequences:


The octal value nnn, where nnn stands for 1 to 3 digits between ‘0’ and ‘7’. For example, the code for the ASCII ESC (escape) character is \033.


The hexadecimal value hh, where hh stands for a sequence of hexadecimal digits (‘0’–‘9’, and either ‘A’–‘F’ or ‘a’–‘f’). A maximum of two digits are allowed after the \x. Any further hexadecimal digits are treated as simple letters or numbers. (c.e.) (The \x escape sequence is not allowed in POSIX awk.)

awk 'NR==90 { print "define(\`RELAY_MAILER_ARGS\047, \`TCP $h 2525\047)dnl"}1' example.com.mc

gawk 'NR==90 { print "define(\`RELAY_MAILER_ARGS\x27, \`TCP $h 2525\x27)dnl"}1' example.com.mc

If you would like to also use \140 (or \x60) to represent the backtick:

awk 'NR==90 { print "define(\140RELAY_MAILER_ARGS\047, \140TCP $h 2525\047)dnl"}1' example.com.mc

gawk 'NR==90 { print "define(\x60RELAY_MAILER_ARGS\x27, \x60TCP $h 2525\x27)dnl"}1' example.com.mc
  • Thanks, there is a subtle trick with Sendmail configuration macros. The first "quote" character is a backtick and the second is a single quote. I understand what the correct answer should be now and thank you so much!! However, I would adjust your answer so that it looks like this: \140RELAY_MAILER_ARGS\047, \140TCP $h 2525\047.
    – Utkonos
    Jan 8, 2023 at 7:43
  • 1
    Thanks, I simply thought it was a typo. Updated my answer to cover this. Hope all the new examples are working as well. Jan 8, 2023 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .