I am new to shell scripting and unix commands and am trying to find a good way to do a lazy match between patterns in a file and haven't been able to get the output I want to see. The text looks like the following example (Edit: Revised text string
"hello
how
are
you
right
now
and
hey how
you
doing
thanks
see
you
and
ask
me if I
am
doing
okay"
Desired output:
hey how
you
doing
I have tried to use multiple answers I found here for similar issues involving sed, grep or awk and I keep seeing this output instead:
how
are
you
right
now
and
hey how
you
doing
thanks
see
you
and
ask
me if I
am
doing
I just want to perform a lazy match between the word "how" and "doing" and print the lines in between (inclusive) (and preferably how to use the solution to assign the returned text to a variable in a shell script)
Thanks in advance
Edit
I just want to perform a lazy match between the word "how" and "doing" and print the lines in between
You may use this awk:
awk 'p{s = s ORS $0} /how$/{p=1; s=$0} p && /doing$/{print s; p=0}' file
hey how
you
doing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With