I’m trying to comment out a line via sed
command.
sudo sed -i "s|Include /etc/ssh/sshd_config.d/*.conf|#Include /etc/ssh/sshd_config.d/*.conf|" /etc/ssh/sshd_config
Why the command above does not work? What am I missing here?
I get no errors, but the line is not commented out.
I’m doing that on a Debian 12 machine.
2
Answers
What you’re using is not matching what you believe. In regular expressions
*
has special meaning.sed
uses regular expressions in its search term and asterisk (*
) is a special character (star quantifier) in this context. The star quantifier means that the preceding expression (here:/
) can match zero or more times.To treat
*
as a normal character replace it in your search term with*
or[*]
.See: The Stack Overflow Regular Expressions FAQ