Find lines with space between strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find lines with space between strings
# 1  
Old 05-06-2008
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  
Old 05-06-2008
Code:
SERVER_CHECK=`echo "$LINE" | egrep "^${APPL_SERVER} *#"`

# 3  
Old 05-06-2008
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  
Old 05-06-2008
Try:

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

Regards
# 5  
Old 05-06-2008
That worked! Thanks for your help.
# 6  
Old 05-07-2008
Quote:
Originally Posted by Galt
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to find multiple strings on different lines in file?

Hello, I have spent considerable amount of time breaking my head on this and reached out here. here is the back ground. OS - Solaris 10 There are two strings '<Orin>sop' and '<Dup>two' which I wanted to look for in a file without the quotes on different lines and ONLY if both strings are... (5 Replies)
Discussion started by: keithTait309875
5 Replies

2. Shell Programming and Scripting

How to find lines in a .txt contains the strings I want

I have a .txt contains a lot of lines. Now I want to write a shell script to find out all the lines which contain the strings I want, and print these lines. For example: A.txt when you post any code you can easily do this highlighting your code and then click you should do a Google... (6 Replies)
Discussion started by: Henryyy
6 Replies

3. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

4. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

5. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

6. Shell Programming and Scripting

Extract lines between 2 strings add white space

I'm trying to extract all the lines between 2 strings (including the lines containing the strings) To make the strings unique I need to include white space if possible. I'm not certain how to do that. sed -n '/ string1 /,/string2/p' infile > outfile & (4 Replies)
Discussion started by: dcfargo
4 Replies

7. Shell Programming and Scripting

Find lines containing two strings

How can i find lines which contains two strings (or two charcters) let say "ABC" and "DEF". Line: SEFGWN;BVABCFSDFBDEF (3 Replies)
Discussion started by: ksailesh
3 Replies

8. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

9. Shell Programming and Scripting

How to find the lines which do not have certain strings

Hi, guys. I have one question: How can I search the lines in a file which do not have certain string in it. For example, the file is called shadow, the contents of it is below: **************************** ... brownj:SFSM$DFAAA2313:0:0:50:7 hynesp:MNBADF$23$adfd:0:0:50:7... (2 Replies)
Discussion started by: daikeyang
2 Replies

10. Shell Programming and Scripting

using AWK see the upper lines and lower lines of the strings??

Hi experts, You cool guys already given me the awk script below- awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log Morever, i have one more things- when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string. Line 1.... (3 Replies)
Discussion started by: thepurple
3 Replies
Login or Register to Ask a Question