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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
recursive grep output f_o_555 UNIX for Dummies Questions & Answers 5 10-02-2008 06:37 AM
Trap grep output edrichard Shell Programming and Scripting 6 08-21-2008 12:20 PM
output of grep useless79 Shell Programming and Scripting 3 09-18-2007 06:36 AM
substitute the grep output jasmeet100 Shell Programming and Scripting 1 10-11-2005 08:40 PM
Strange output from grep Bab00shka UNIX for Dummies Questions & Answers 10 11-09-2004 06:23 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 10-23-2008
yoom@hostwebase yoom@hostwebase is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 4
GREP with contain output

How can I perform a grep and it will give me a contain word (maintenance) instead of a string or the whole line of info.

grep with exclusive output?
or is there a CONTAIN with IF statement ?


I have a file call yast2_vhost.conf and it contain multiple entries call
maintenance.html
/srv/www/maintenance/
/srv/www/maintenance/maintenance.html ..etc


******************************************************
#!/bin/ksh
result=$(grep "maintenance" /etc/apache2/yast2_vhost.conf)

if [[ $result = maintenance ]]; then
echo "you messed up"
else
cp /etc/apache2/orginal.conf /etc/apache2/current.conf
fi

********************************************************
  #2 (permalink)  
Old 10-23-2008
vimes vimes is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 46
Quote:
Originally Posted by yoom@hostwebase View Post
or is there a CONTAIN with IF statement ?
Several ways to do that. For example, have a look at "grep -c". Check the manpage if needed. It returns the number of matches found by grep. If you put that in a var, you can then check the var in your if statement.


Code:
$count = `grep -c bla /myfile`
if [[ $count -gt 0 ]]; then
...
fi

  #3 (permalink)  
Old 10-23-2008
yoom@hostwebase yoom@hostwebase is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 4
VIMES,

Thank you for your respond and ideas.

I looked at grep manpage and was able to find a flag that will work for my case. It is the -o

Thanks again.

Y
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 09:07 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