regex - Matching a sentence with grep -


i'm trying grep full sentence containing search term. i've tried

grep (^.|\.\s).*searchterm.*(\.\s|\n) 

but it's not working , i'm not sure why.

to clarify: want stdout print full sentence of search term. using grep search through single text file.

as example, if file has

"foo blah. blah blah searchterm blah blah. foo bar."

i want stdout print blah blah searchterm blah blah

because normal grep uses bre in have write capturing groups \(...\) , alternation operator \| . ( or ) or | alone match it's corresponding literal ( , ), | chars.

grep '\(^.\|\.\s\).*searchterm.*\(\.\s\|\n\)' 

or

grep '\(^.\|\.[[:space:]]\).*searchterm.*\(\.[[:space:]]\|\n\)' 

or

enable -e or -p parameter.

grep -p '(^.|\.\s).*searchterm.*(\.\s|\n)' 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -