Você pode fazer:
grep '^[^#]*MYSTRING' file.txt
-
^[^#]*MYSTRINGcorresponde a qualquer número de caracteres do início que não seja#, atéMYSTRING, ou seja, corresponde às linhas que têmMYSTRING, mas não#em qualquer lugar antes disso na linha
Exemplo:
% cat file.txt
# another line above is commented but that's not on the same line
a=1; MYSTRING
a=1 # otherstring MYSTRING
% grep '^[^#]*MYSTRING' file.txt
a=1; MYSTRING