I need to find all files that contain MYSTRING which do not have a # before that.for instance this one should return FALSE as there is an occurrence of # before MYSTRING in the same line:a=1      #  otherstring  MYSTRINGand this one should return TRUE: # another line above is commented  but that's not on the same line     a=1; MYSTRINGI have checked in the similar questions, but couldn't find exactly the same situation.
grep files that contain a non commented text
grep
You can do:grep '^[^#]*MYSTRING' file.txt^[^#]*MYSTRING matches any number of characters from start that is not #, upto MYSTRING i.e. it matches lines that have MYSTRING, but no # anywhere before that on the lineExample:% cat file.txt # another line above is commented  but that's not on the same line     a=1; MYSTRINGa=1      #  otherstring  MYSTRING% grep '^[^#]*MYSTRING' file.txt     a=1; MYSTRING