Find lines with space between strings

Hello all,

I am having trouble with setting up a regular expression used with egrep. My script reads an input file a line at a time. I would like the egrep command to search for the following pattern: server name at the beginning of the line, then one or more spaces, and then a pound sign.

A line like this would match:
SERVERNAME #

A line like this would not match:
SERVERNAME#

The line in my code that I'm using the egrep command is:
SERVER_CHECK=`echo $LINE | egrep ^${APPL_SERVER}[[:space:]]*\#`

This is not returning the lines that I know match the pattern I'm looking for. Can anyone help me modify my regular expression?

Thanks for your help.

SERVER_CHECK=`echo "$LINE" | egrep "^${APPL_SERVER} *#"`

Thanks robotronic, but it is still returning strings with no spaces between the server name and pound sign. Is there a way to say at least 1 or more spaces?

Try:

 SERVER_CHECK=`echo $LINE | egrep "^${APPL_SERVER}[ ]+#`

Regards

That worked! Thanks for your help.

Sorry Galt, I've misread your request. If you want to use an utility which doesn't recognize extended regexp (like the plus "+" sign on Solaris' grep) you can try this:

SERVER_CHECK=`echo "$LINE" | egrep "^${APPL_SERVER}  *#"`

In other cases Franklin's code is more suitable and readable :slight_smile: