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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -