![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 ******************************************************** |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|