sed: unknown command
Fix the sed 'unknown command' error caused by unescaped special characters or incorrect delimiter syntax.
sed: unknown command
sed produces "unknown command" when the expression contains unescaped special characters or uses an incorrect delimiter.
When sed Produces This Error
sed displays
-e expression #1, char X: unknown command: 'Y' where
Y is the character sed could not parse.
What Causes "unknown command" in sed
The most common cause is using
/ as a delimiter when the pattern or replacement contains
/. sed interprets the extra
/ as the end of the expression, leaving the remainder as an unrecognized command.
How to Fix "unknown command" in sed
Use an alternative delimiter when working with file paths or URLs:
sed 's|/var/log/old|/var/log/new|g' config.confEscape special characters in the pattern:
sed 's/\/var\/log\/old/\/var\/log\/new/g' config.conf
The first approach (alternative delimiter) is preferred for readability.