how to know if a string contains a certain pattern

say i want to know if string1 contains string2.
thanks a lot!

echo $string1 | grep -c $string2

thank you!

a=bigfish
b=fish
echo $b  | awk -v var=$a '{ if ( match(var, $0) && length < length(var) ) { print "yes" } else { print "no" } }'

Awk without parsing:

string1="holacaracola"                                              
string2="hola"                                                      
echo $string1|awk '{if (match($0,/'"${string2}"'/)){print "MATCH"}}'
MATCH

Matrixmadhan, Klashxx, I am very bad at awk and sed. And, im not sure if these will work with csh? I tried them both and got:
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1

In csh it would be ( for example )

set a=bigfish
set b=fish
echo $b  | awk -v var=$a '{ if ( match(var, $0) && length < length(var) ) { print "yes" } else { print "no" } }'

however this would be simpler:

set a=bigfish
set b=fish

echo $a | awk -v b="$b" '$0 ~ b { print "MATCH" }'

Reborg, neither of them works... I still get the same errors:
awk: syntax error near line 1
awk: bailing out near line 1

Try nawk instead of awk.

The following worked!

echo $b | nawk -v var=$a '{ if ( match(var, $0) && length < length(var) ) { print "yes" } else { print "no" } }'

But this one didnt:

echo $a | nawk -v b=$b '$0 ~ b { print "MATCH }'

Error message was:

nawk: syntax error at source line 1
context is
$0 ~ b { print "MATCH >>> } <<<
nawk: illegal statement at source line 1
missing }

Really, I have to start studying awk (and nawk)...

You are missing a quote on the second one.

"MATCH should be "MATCH"

Yes, I missed the ".
Thanks guys!