Bash: using grep to extract text from strings

I have a text file that reads like this:

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

I am trying to extract:

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

so everything is between “We” and “GOOD,” including two words.

I use the command:

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

But it does not work (it does not stop after HOORAY). How can i fix this? Is there any other way to get closer to the team?

+4
source share
1 answer

This simple one sedcan help you with this.

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

Solution 2nd: Use awktoo.

awk '/We\047re/,/HOORAY/'  Input_file
+2
source

Source: https://habr.com/ru/post/1695557/


All Articles