if statement

I am having problem writing the following script, this is more like a boolean case where i need to check for existance of a string in a file and if it exist i have to do certain things.

If ( such string exist in a file)

sed 's/car/bus/g' file

else

do something else.

To check for the existance of a string in a file you can use grep.

grep "string" file

Read the man page of grep

Regards

I dunno how I can ask this question. It seems like that I am not expressing my question correctly becuz i am not getting anything related to my question. I am not having problem with searching a string. I don't know how to use that output for if statement. lets say i do GREP STRING FILENAME this would give me either an output or nothing. I want to use this output as a condition to do my if statement but i dunno how to go about using this output. i mean what i have to use in order to get a condition out of this.

lets say we use
If ["$A" lt 0]; then .... but in my case i dunno what exactly i have to use for GREP SRTING FILENAME to see if this actually gives an output or it is NULL

I want something like If( GREP STRING FILENAME give me an output) do the following......

I hope someone has an answer for me
Thanks

#! /bin/ksh

str='grep 'string' filename | wc -l'
if (($str >= 1)); then
     sed 's/car/bus/g' file
else
     exit 0
fi

Thx for the quick response. it is exactly what I was looking for.

The 'if ' better (I believe ti was desighned for that usage) to use in that way:

if grep $str $file_name &>/dev/null; then ...; ...; else ...; ...; fi;

The if acting on return code from command ('grep' here) - (return in shell could be checked by '$?' right after execution a command.)

The '&>/dev/null' part redirect any returns or/and error infor into nowhere, as the result is not interesting here, but only return code

First, you don't need wc.

Second, those should be backticks, not apostrophes:

str=`grep -c 'string' filename`

You can do exactly the same thing using the standard syntax:

if [ $str -ge 1 ]; then

Do you need to keep the output of grep (if any)?

If not, just test whether grep is successful:

if grep 'string' FILENAME > /dev/null; then
   echo YES
else
   echo NO
fi