I have found lots of guides for ignoring lines with comments or matching for one string but not another, but I have not found what I need. I want to grep recursively for files containing the string indexes (case insensitive i think, it's apache conf) but not a # BEFORE it. It should match this:Options IndexesOptions +IndexesOptions Indexes MultiViewsOptions Indexes # CommentOptions Indexes # IndexesBut not this:Options MultiViews # Indexes# Indexes yadayada IndexesI'm using it in a script on the form:if grep -re [^#]*ndexes $DIR1/httpd.conf $DIR2/http; then    echo Do not use IndexesfiThe above is one of my efforts, but I cannot get it to work.
grep for string without another string before it
grep;regular expression
Given this input:Options IndexesOptions +IndexesOptions Indexes MultiViewsOptions Indexes # CommentOptions Indexes # IndexesOptions MultiViews # Indexes# Indexes yadayada IndexesThis appears to work:$ grep '^[^#]*Indexes' inputOptions IndexesOptions +IndexesOptions Indexes MultiViewsOptions Indexes # CommentOptions Indexes # Indexes$ grep -v '^[^#]*Indexes' inputOptions MultiViews # Indexes# Indexes yadayada IndexesTo dissect the regular expression:^ - Beginning of the line[^#]* - Zero or more of any character that is not an octothorpeIndexes - The literal string IndexesTo put it in the context of your script:if grep -rl -- '^[^#]*Indexes' $DIR1/httpd.conf $DIR2/http; then    echo The above-listed files use an 'Indexes' directive.fi