Question

How to cat or echo everything between two words in a file ?

eg

df
df
Instance 
d
f
g
end

So I want everything between Instance and end

Thanks

Was it helpful?

Solution

This might work for you (GNU sed):

sed -n '/^Instance/,/^end/{//d;p}' file

or as Glenn pointed out:

sed -n '/^Instance/,/^end/{//!p}' file

OTHER TIPS

This should be correct awk

awk '/end/{f=0} f; /Instance/{f=1}' file
d
f
g

PS, data was not in one line. OP was missing code tags, so showed all in one line ...

awk '{match($0,/Instance(.*)end/,a); print a[1]}' input.txt

Output:

 d f g 
sed -n '/^Instance/,/^end/{/^Instance/!{/^end/!p}}' file
d
f
g
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top