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
Post a Comment