Need regex for line not starting with hash #

I need to search for lines starting with "Include" and later has string "httpd-ssl.conf"

like the regex should return match for "Include conf/extra/httpd-ssl.conf"

I tried the following:

^[[:blank:]]*[^[:blank:]#;].+Include.*httpd-ssl.conf

Below is my current file:

# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf

   #Include conf/extra/httpd-ssl.conf
#  Include conf/extra/httpd-ssl.conf
#Include conf/extra/httpd-ssl.conf


#
# Note: The following must must be present to support
# 

This should not match anything but if you try my sample text and regex in regex101.com or any online regex checker it matching the first entry which has new line as a "newline".

#Include conf/extra/httpd-ssl.conf

<MATCHES IF ABOVE IS A NEWLINE>

How can we make sure that the first visible charecter of a line should be string "Include" and preceeded by string " "httpd-ssl.conf""

Please post EXACTLY what you want your final output should be after REGEX.

Please post your operating system as well.

Given the sample data i expect regex to return NOTHING it should NOT MATCH anything but unfortunately it does.

Mine is a Oracle Linux system.

Sorry, I cannot follow what you want, exactly.

Maybe someone else has more time to decipher what exactly you want.

Don't worry, your overcomplicated regex doesn't match anything reasonable in your file, if that is what you're after (not clear from your spec). Even uncommented lines with # removed (which I added to your sample file) aren't matched:

$ grep "^[[:blank:]]*[^[:blank:]#;].+Include.*httpd-ssl.conf" file
$ grep -E "^[[:blank:]]*[^[:blank:]#;].+Include.*httpd-ssl.conf" file
$ sed -n '/^[[:blank:]]*[^[:blank:]#;].+Include.*httpd-ssl.conf/p' file

You could have tried yourself on your "Oracle Linux system", also questioning your online regex tester.

See the detailed, step by step analysis of your regex (culprit seem to be items 3 and 4):

^[[:blank:]]*[^[:blank:]#;].+Include.*httpd-ssl.conf


^                       # start of line
[[:blank:]]*            # any number of space, TAB, newline
[^[:blank:]#;]          # ONE char non-blank, non-#, non-;
.+                      # ONE or many chars, whichever
Include                 # string constant "Include"
.*                      # any number of any char
httpd-ssl.conf          # string constant
2 Likes

@Rudic thank you for the explanation.

Let's consider a sample file like below:

    
    530 #Include conf/extra/httpd-ssl.conf
    531
    532      Include conf/extra/httpd-ssl.conf
    533 #  Include conf/extra/httpd-ssl.conf
    534 Include conf/extra/httpd-ssl.conf
    535 #    Include conf/extra/httpd-ssl.conf
    536 #Include conf/extra/httpd-ssl.conf
    537 #

Note: the left numbering(5**) is only the line number populated using set nu of vi editor and not the actual file content.

The explanation that you gave for my regex should atleast match line number "532" but it does not.

Line number "532" passes all of the below but the command still fails to yeild any matches(output):

^                       # start of line
[[:blank:]]*            # any number of space, TAB, newline
[^[:blank:]#;]          # ONE char non-blank, non-#, non-;
.+                      # ONE or many chars, whichever
Include                 # string constant "Include"
.*                      # any number of any char
httpd-ssl.conf          # string constant

Can you please explain why ?

Nevertheless the below regex works for me and gets me unhashed lines starting with "Include" followed by "httpd-ssl.conf"

# grep -E "^[[:blank:]]*[^[:blank:]#;].+Include.*httpd-ssl.conf" /tmp/httpd.conf
Fails for the sample data shared in this post for reasons I wish to know 
# grep -E "^[^#]*Include.+httpd-ssl.conf" /tmp/httpd.conf
   Include conf/extra/httpd-ssl.conf
Include conf/extra/httpd-ssl.conf
Passes.
[^[:blank:]#;]          # ONE char non-blank, non-#, non-;
2 Likes

Thank you as it helped resolve the problem.