novel
novel

Reputation: 79

bash: using grep to extract text from between strings

I have a text file that reads like:

hello
We're so
excited to 
be learning computer
science today
    HOORAY
hooraaaay

I'm trying to extract:

We're so
excited to 
be learning computer
science today
    HOORAY

so everything between "We're" and "HOORAY" including the two words.

I'm using the command:

sed -n "/^We're so/,/^    HOORAY/p" file.txt

But it's not working (it doesn't stop after HOORAY). How would I fix this? Is there another way to approach the command?

Upvotes: 4

Views: 71

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133528

This simple sed may help you on same.

sed -n "/We're/,/HOORAY/p"   Input_file

Solution 2nd: Using awk too.

awk '/We\047re/,/HOORAY/'  Input_file

Upvotes: 3

Related Questions