sed - Adding a comment character in most simple possible way -
i want search file specific string , place comment @ beginning of string. need answer avoids regex, global changes, , other fancy stuff.
i wrote line:
sed -i.bak '/permitrootlogin no/# permitrootlogin no/' ./sshd_config
but error:
sed: -e expression #1, char 21: comments don't accept addresses
i assume issue need escape # character, i'm not finding resources on how that, or mentioning it. i've tried various combinations of putting ^ or \ or \^ in front of # i'm jut not getting right.
please note intentionally repeating text replaced. simple possible solution question: how replace "xyx" "# xyz" in obvious possible way.
as indicated in comments @mlt , try adding s @ beginning sed command. straight comment:
s/permitrootlogin....
i see said you're intentionally repeating test replaced. if mean, want same, maybe consider grouping matched text. understand may have meant want hand typed. anyway, here how match grouped text , add comment character:
s/(permitrootlogin)/# \1/
the parens indicated matched text should consider group, \1 indicates want put matched group there.
i hope helpful. happy coding! leave comment if have questions.
Comments
Post a Comment