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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do I search a File for a string exact match CAGIRL Shell Programming and Scripting 3 07-29-2008 01:20 AM
search excat string in another string (grep "fails") bora99 UNIX for Dummies Questions & Answers 0 06-05-2008 06:41 AM
grep for a search string raga UNIX for Dummies Questions & Answers 11 03-12-2008 08:38 AM
grep: RE error 41: No remembered search string. fkaba81 Shell Programming and Scripting 2 06-22-2006 02:23 AM
sed, grep, awk, regex -- extracting a matched substring from a file/string ropers Shell Programming and Scripting 2 05-23-2006 01:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-03-2008
albertashish albertashish is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Exclamation grep exact string/ avoid substring search

Hi All,

I have 2 programs running by the following names:
a_testloop.sh
testloop.sh

I read these programs names from a file and store each of them into a variable called $program.
On the completion of the above programs i should send an email.
When i use grep with ps to see if any of these are running i cannot differentiate between the two.

I am using the following command:
ps -ef|grep $program|grep -v grep

The above command succeeds for both the cases even when only a_testloop.sh is running as testloop.sh is a part of a_testloop.sh. I want to grep/search only the exact string not substring. Please help.

Thanks,
Albert
  #2 (permalink)  
Old 11-03-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Use the -w option of grep.

Regards
  #3 (permalink)  
Old 11-03-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool

what about
1) grep for a_testloop will give you just that
2) grep for testloop and then grep -v a_testloop to exclude that one
  #4 (permalink)  
Old 11-03-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
The ps-output is tabular, right?

You can search for whitespace too, if you protect them properly (otherwise the shell will eat them):

Code:
# cat myfile
 testloop
 a_testloop

# grep '[<spc><tab>]testloop' myfile
 testloop
# grep '[<spc><tab>]a_testloop' myfile
 a_testloop
Replace <spc> by a literal blank and <tab> by a literal tab character.

I hope this helps.

bakunin
Closed Thread

Bookmarks

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 02:15 AM.


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