Content of my filename file is as following(for example):
My block of line starts from here
START
First line
second line
third line
END
and end to here for example.
I want to replace block of lines between START and END with just a single word, for example with SINGLEWORD. Like below:
My block of line starts from here
SINGLEWORD
and end to here for example.
I can find my block of lines with using this command:
grep -Pzo "START(.|\n)*END" filename
And the result of running above command will be like this:
START
First line
second line
third line
END
Then I used this command to combine all lines into a single line:
LAST_RESULT | sed -e :a -e '/$/N; s/\n/ /; ta'
Then I will get this result:
START First line second line third line END
And with my last command LAST_RESULTS | sed 's/.*/SINGLEWORD/' I change them to "SINGLEWORD" and I get this result.
SINGLEWORD
Now what I want is: How can I use this command(Or your suggestion command) and replace(in place)my block of lines to "SINGLEWORD" word? And the final result will be like this file:
My block of line starts from here
SINGLEWORD
and end to here for example.