Sed remove between patterns
by pedropt from LinuxQuestions.org on (#4VBKS)
This code is probably here already in the forum , but search engine did not poped up any results for what i need .
And what i need is pretty simple , use sed to remove everything between 2 patterns , but do not remove the patterns .
Example :
#starthere
dwfwef
efewf
wefewf
#endhere
Desired output
#starthere
#endhere
This next code removes also the patterns , but i dont want them to be removed , i want only what there is between them .
Code:sed -i "/\#starthere/,/\#endhere/d" myfile


And what i need is pretty simple , use sed to remove everything between 2 patterns , but do not remove the patterns .
Example :
#starthere
dwfwef
efewf
wefewf
#endhere
Desired output
#starthere
#endhere
This next code removes also the patterns , but i dont want them to be removed , i want only what there is between them .
Code:sed -i "/\#starthere/,/\#endhere/d" myfile