The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 04:13 AM
replace 2 identical strings on different lines prkfriryce Shell Programming and Scripting 3 06-15-2007 12:18 PM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 11:27 AM
many strings against 5million lines r0sc0 Shell Programming and Scripting 2 01-19-2006 09:04 PM
How to select strings with space? nir_s Shell Programming and Scripting 4 05-09-2005 10:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-06-2008
Galt Galt is offline
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.
  #2 (permalink)  
Old 05-06-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
SERVER_CHECK=`echo "$LINE" | egrep "^${APPL_SERVER} *#"`
  #3 (permalink)  
Old 05-06-2008
Galt Galt is offline
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?
  #4 (permalink)  
Old 05-06-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,309
Try:

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

Join Date: Mar 2008
Posts: 3
That worked! Thanks for your help.
  #6 (permalink)  
Old 05-07-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
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
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0