I am trying to use sed to overwrite my index.php file, but I am getting an error:
$ sed -i \'s@@
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'
<<< ''
construct will pipe '
as standard input$'...'
construct will be parsed for special characters. In this case the \n
splits the string into two linesStandard 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