The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print only lines in between two strings using awk jisha Shell Programming and Scripting 4 01-11-2008 12:13 AM
replace 2 identical strings on different lines prkfriryce Shell Programming and Scripting 3 06-15-2007 08:18 AM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 07:27 AM
many strings against 5million lines r0sc0 Shell Programming and Scripting 2 01-19-2006 05:04 PM
How to select strings with space? nir_s Shell Programming and Scripting 4 05-09-2005 06:22 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-06-2008
Registered User
 

Join Date: Mar 2008
Posts: 3
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-06-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
SERVER_CHECK=`echo "$LINE" | egrep "^${APPL_SERVER} *#"`
Reply With Quote
  #3 (permalink)  
Old 05-06-2008
Registered User
 

Join Date: Mar 2008
Posts: 3
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?
Reply With Quote
  #4 (permalink)  
Old 05-06-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,561
Try:

Code:
 SERVER_CHECK=`echo $LINE | egrep "^${APPL_SERVER}[ ]+#`
Regards
Reply With Quote
  #5 (permalink)  
Old 05-06-2008
Registered User
 

Join Date: Mar 2008
Posts: 3
That worked! Thanks for your help.
Reply With Quote
  #6 (permalink)  
Old 05-07-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Quote:
Originally Posted by Galt View Post
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?
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:

Code:
SERVER_CHECK=`echo "$LINE" | egrep "^${APPL_SERVER}  *#"`
In other cases Franklin's code is more suitable and readable
Reply With Quote
Google UNIX.COM
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0