sed permission denied when overwriting file

前端 未结 9 580
我在风中等你
我在风中等你 2021-01-11 12:07

I am trying to use sed to overwrite my index.php file, but I am getting an error:

$ sed -i \'s@@

        
9条回答
  •  天涯浪人
    2021-01-11 12:45

    If the use of sed is not a hard requirement, you can probably use the highly ignored command ed.

    ed -s index.php <<< $'%s@@@\nwq'

    • The <<< '' construct will pipe '' into the as standard input
    • The $'...' construct will be parsed for special characters. In this case the \n splits the string into two lines
    • You can use any construct you want to generate and pipe in the input (echo, printf, etc.)

    Standard Input String:

    %s@@@
    wq
    

    The first line is your regex search and replace as command for ed. The second line tells ed to write the changes and quit. You may recognize these commands from vi.

    source: mrbluecoat.blogspot.com/2014/03/in-place-editing-right-way-hint-dont.html

提交回复
热议问题