sed -n '/Start/,/End/ {
/Start/ !{
/End/ !H
}
/End/ {
s/.*//
x
s/\n/:/g
s/://
p
}
}
/Start/,/End/ !p' YourFile
If start
and Start
should work replace Start
by [sS]tart
(and End
by [eE]nd
) in the code
Explaination
Start sed without printing the ouptut unless specific request
/Start/,/End/ {
For any block of line starting with Start
and ending with End
(on separate line)
/Start/ !{
/End/ !H
}
if line doesn not contain (the !
) Start
than End
, Add (append) the line to the holding buffer (kind of storage)
/End/ {
s/.*//
x
s/\n/:/g
s/://
p
}
when reach the line that contain End
- Delete current line (the one with
End
)
- exchange (
x
)the Hold Buffer (with all line of the bloc stored) and Working Buffer (the one that can be manipulate and normaly have the current line)
- Change all new line with
:
(the buffer contain all the line separate by new line after exchange)
- remove first
:
(due to first Append that insert a new line)
print the content
/Start/,/End/ !p
for all the line not ( !
) between the block between Start
and End
, print it