How to search for a pattern a string?

Hi all,

I'm new in UNIX , so how to check if stringA is present within stringB ?

Something similar to INSTR function in pl sql...

Thanks a lot.

Try:

echo `expr index "$stringB" "$stringA"`

Regards

Not sure if this works???

Sorry, probably misstyped it , so how it works?
If it returns '1' then stringB is within stringA , right?

Here is a simple example that will work with both bash and ksh93

stringA="POLICY"
stringB="CUSTOMER HOUSEHOLD QUOTE POLICY"

if [[ $stringB =~ $stringA ]]
then
    echo "YES, stringA is present in stringB"
else
    echo "NO, stringA is not present in stringB"
fi

!/usr/bin/ksh93

check that your version of ksh is actually ksh93. It is not ksh93 if the following does not work

echo ${.sh.version}

You may have pdksh or ksh88.

Got this, what does that mean?

Given your shell version, it should be easier with case:

case $stringA in 
  *$stringB* ) echo OK;;
           * ) echo KO;;
esac

That your shell is not ksh93.

Nope does not work again :confused:

It should be stringB in ... stringA:

$ stringA=POLICY
$ stringB="CUSTOMER HOUSEHOLD QUOTE POLICY"
$ case $stringB in        
> *$stringA*) echo OK;;
> *) echo KO;;
> esac
OK

Thanks a lot!!!:b: