I have to replace a large block of a text (shell script code) in a file with another block of text.
But I have some trouble in using them.
antak already mentioned in his answer that streaming entire file (
1h;2,$H;$!d;g;) to the buffer is not advisable for large files, because it overload memory.
sedcan be used with the block feature to preserve the text outside the block unchanged. I want to use this feature. But if I use,
sed -i '/marker1/,/marker2/s/.*/new text (code)/' filename
it will insert new text (code) repeatedly for each stream. Hence I have to make the visual block as one stream, using something similar to what suggested by antak earlier, but for the block (not for entire file).
As mentioned by Bruce Ediger append feature of
exwhich begin with
.(dot) can be tried, but my new text (code) contain lines begin with dot, which may be considered as the dot of append syntax. How can I use it in this situation?
dd'number of lines' may delete multiple lines, but if I have a block between /marker1/ and /marker2/ with the number of lines not fixed (varying) is to be replaced with new text (code), how to do it ?