How can I grep the string which is only in uncommented line? I don't want the result to be included for string in commented line. For example: In file.tx
My name is Jane
#My name is Sara
I want to grep word "name" and print the output, like below: -
My name is Jane
But I don't want the commented line to be display to.
Thanks
grep '^[^#]*pattern'
, to prevent any#
from creeping in anywhere before the pattern), may I suggest posting that as an answer? – Stephen Kitt Nov 28 '18 at 09:46echo "# pattern"
which is not a comment. – pLumo Nov 28 '18 at 10:10'^[^#].*pattern
) solution is broken -- it will miss lines wherepattern
should match at the beginning of the line. – Nov 28 '18 at 15:41